Strange STL ostringstream compile error with Visual Studio 2005

I have just installed Visual Studio 2005 and am building a project formerly maintained under VC++ 6.0.

The compile error I cannot fathom pertains to STL, specifically it appears to be related to my use of ostringstream. I believe I have isolated the problem to one of my header files where I use the ostringstream class. However, my use of this class is obviously limited to the public interface which is why the compile error below makes no sense to me.

btw, I have already changed all header files to reflect the new C++ usage (e.g. <sstream.h> is now <sstream>)

Here is the compile error:

**********************************************************
Compiling...
ligandandtarget.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\include\sstream(448) : error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\ios(151) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This diagnostic occurred in the compiler generated function 'std::basic_ostringstream<_Elem,_Traits,_Alloc>::basic_ostringstream(const std::basic_ostringstream<_Elem,_Traits,_Alloc> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
***************************************************************




Answer this question

Strange STL ostringstream compile error with Visual Studio 2005

  • Narcis Calvet

    Thanks, the constructor issue was the problem.

    Why this happens is beyond me (nothing I've found online or in my STL text explains it).

    The class was a ref-counted class that maintained a ostringstream as a member. The problem was with the class' default constructor; apparently generating the code to instante an ostringstream caused the compiler some problems.

    I modified the class to use a dynamically allocated ostringstream and it at least compiles.

    I'll try testing it today and see if it works.

    Thanks again!

    Cheers,
    Mark

  • mc_hk

    The Standard C++ library implementation in VS2005 is more conformant than the one in VC6, and this is probably the issue here.

    Can you post the code within ligandandtarget.cpp that causes this to occur You should cut away irrelavant code in order to keep the post short.

    Thanks,

    Brian


  • jeymard

    Hi,
    are you using the copy constructor in those lines If you're doing something like this:
    ostringstream a;
    ostringstream b(a); // error, cannot access private member ...

    then you'll get the error.


  • Strange STL ostringstream compile error with Visual Studio 2005