Re: ostream constructor error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Julian wrote:
> I have this piece of code that is working fine in VC6... but when i
> tried to compile the same code in VC++.NET, I am getting this error :
>
> error C2512: 'std::basic_ostream<_Elem,_Traits>' : no appropriate
> default constructor available
>        with
>        [
>            _Elem=char,
>            _Traits=std::char_traits<char>
>        ]
>
> i had also changed #include <fstream.h> to #include <fstream>
> and added this line "using namespace std;"
Ok, but do you understand why these changes are necessary? VC6 used a 
non-standard "stream" implementation, whereas CV7 conforms to what is 
dictated in the C++ standard concerning streams. The documentation for 
standard ostream is here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrf_ostream_Ostream.asp?frame=true
It shows us that std::ostream is really a typedef for 
std::basic_ostream<char>, and the only constructor for this typeis defined 
here : 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrf_ostream_basicostreambasicostream.asp?frame=true
As you can see, the constructor needs a basic_streambuf argument. Therefore, 
you need to provide a streambuf for the constructin of the base clas ostream 
of your ArgumentOstream class. Not knowing your whole code,I can't be sure, 
but U guess your constructor should be :

ArgumentOstream(Arguments &args, ostream &o=cout)

: ostream(o.rdbuf())
{
  //no call to init : it is done through the base class constructor
  //...
}

Arnaud
MVP - VC


.



Relevant Pages

  • Re: ostream constructor error
    ... >> I have this piece of code that is working fine in VC6... ... the constructor needs a basic_streambuf argument. ... > clas ostream of your ArgumentOstream class. ... but now i realize that it was basically because of the base class ostream: ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Pattern suggestion for processing similar image types
    ... This approach would constrast with a trivial constructor ... Therefore I think your concerns are really those of the "factory" object ... If the stream used to instantiate the PGM is unique the the ...
    (comp.object)
  • Re: throwing exception from constructor
    ... This would create a three-state stream - closed, ... appropriate arguments to the FileStream constructor. ... one calls the static method rather than using the constructor, ... extra complexity, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Creating an object that is read from an input stream.
    ... >> Should the Box class have a default constructor? ... The stream code is almost the same. ... for a graphics library of mine I wrote two rectangle classes. ... All drawable objects are defined in virtual ...
    (comp.lang.cpp)
  • Re: Creating an object that is read from an input stream.
    ... >> You can throw an exception if that happens. ... The default constructor can create a Box that's valid. ... If you have a default constructor the stream code ... > I don't know what Rectangle class you are referring to. ...
    (comp.lang.cpp)