How compile "String inf = static_cast<ostringstream*>(&(ostringstream() << pAct.minArea))->str();"
Pietro Cerutti
gahr at FreeBSD.org
Mon Nov 14 14:38:10 UTC 2016
On 2016-11-14 14:39, Otacílio wrote:
> Em 14/11/2016 06:29, Pietro Cerutti escreveu:
>> On 2016-11-09 02:37, Otacílio wrote:
>>> I'm trying create a patch to OpenCV 3.1 runs on FreeBSD but clang
>>> don't compiles lines like this:
>>>
>>> String inf = static_cast<ostringstream*>(&(ostringstream() <<
>>> pAct.minArea))->str();
>>
>> There's nothing wrong with this code, provided that:
>>
>> * <sstream> is included
>> * ostringstream is actually std::ostringstream
>> * pAct.minArea defines operator<< to std::ostringstream or one of its
>> base classes
>>
>> What's the error you're getting?
>>
>> That being said, I'd switch to using c++11 and String inf =
>> std::to_string(pAct.minArea) :)
>>
>
> Hi
>
> This code is in
> /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp/detect_mser.cpp
> line 76 . I'm using C++11. The full compiler error message is this:
>
>
> [ 95%] Built target example_image_sequence
> --- samples/cpp/CMakeFiles/example_select3dobj.dir/all ---
> /usr/bin/make -f
> samples/cpp/CMakeFiles/example_select3dobj.dir/build.make
> samples/cpp/CMakeFiles/example_select3dobj.dir/depend
> --- samples/cpp/CMakeFiles/example_select3dobj.dir/depend ---
> cd /usr/ports/graphics/opencv3/work/opencv-3.1.0 &&
> /usr/local/bin/cmake -E cmake_depends "Unix Makefiles"
> /usr/ports/graphics/opencv3/work/opencv-3.1.0
> /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp
> /usr/ports/graphics/opencv3/work/opencv-3.1.0
> /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp
> /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp/CMakeFiles/example_select3dobj.dir/DependInfo.cmake
> --color=
> --- samples/cpp/CMakeFiles/example_detect_mser.dir/all ---
> /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp/detect_mser.cpp:76:46:
> error: cannot take the address of an rvalue of type
> 'std::__1::basic_ostringstream<char, std::__1::char_traits<char>,
> std::__1::allocator<char> >'
> String inf = static_cast<ostringstream*>(&(ostringstream() <<
> pAct.minArea))->str();
> ^
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oh, of course :) you could force runtime polymorphism by turning the
temporary into a reference, like this:
String inf = static_cast<const ostringstream&>(ostringstream() <<
pAct.minArea).str()
--
Pietro Cerutti
gahr at FreeBSD.org
PGP Public Key:
http://gahr.ch/pgp
More information about the freebsd-ports
mailing list