[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-devel
Subject:    Re: C++ question
From:       Andre Poenitz <poenitz () htwm ! de>
Date:       2003-02-14 13:58:19
[Download RAW message or body]

On Fri, Feb 14, 2003 at 01:43:50PM +0000, Angus Leeming wrote:
>  why does this compile:
>         string data = ...;
>         istringstream datastream(data);
>         LyXLex lex(0,0);
>         lex.setStream(datastream);
> 
> and this not:
>         LyXLex lex(0,0);
>         lex.setStream(istringstream(data));
> 
> The compiler complains that it is expecting a std::istream & and got a 
> std::stringstream. Is it an lvalue thing? (passed & not const & so I guess 
> that the stream is modified...)

The stream has to be modifiable, otherwise you won't be able to wrtie to
it.

istringstream(data) creates a temporary object which cannot be bound to a
non-const ref. I personally think this is a stupid restriction, but Those
Who Know decided otherwise.

Using an explicit temporary variable is the accepted way to handle this...

Andre'


-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic