Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Nov 2016 15:38:05 +0100
From:      Pietro Cerutti <gahr@FreeBSD.org>
To:        =?UTF-8?Q?Otac=C3=ADlio?= <otacilio.neto@bsd.com.br>
Cc:        owner-freebsd-ports@freebsd.org, freebsd-ports@freebsd.org
Subject:   Re: How compile "String inf = static_cast<ostringstream*>(&(ostringstream() << pAct.minArea))->str();"
Message-ID:  <31a0dab8289c0a62d8f8b4c041aefdee@FreeBSD.org>
In-Reply-To: <eba49b50-fd4e-1bd0-fd41-d67424cebb96@bsd.com.br>
References:  <ebbf89d2-f83a-b03a-95db-05c7d5358aa7@bsd.com.br> <d6f25afe1529486ce23d1d0945e87464@FreeBSD.org> <eba49b50-fd4e-1bd0-fd41-d67424cebb96@bsd.com.br>

next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org

PGP Public Key:
http://gahr.ch/pgp



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?31a0dab8289c0a62d8f8b4c041aefdee>