vc6 -> vc7 problem with code (error C2558)

3

3doutpost

can anyone tell me why this won't compile under vc7.1 but compiled
under vc6?

#include <iostream>

template < class implementor >
class streamTest
{
public:
streamTest ( implementor& srcIn ) :
writer ( srcIn )
{
}

streamTest ( const streamTest& orig ) :
writer ( orig.writer )
{
}

streamTest < std::eek:stream >& operator<< ( std::eek:stream& (
__cdecl *ftor ) ( std::eek:stream& ) )
{
( *ftor ) ( writer );
return *this;
}

template < class optor > streamTest& operator<< ( const optor&
optorA )
{
writer << optorA;
return *this;
}

private:
implementor writer;
};

int main ( int argc, char* argv [] )
{
streamTest < std::eek:stream > each ( std::cout );

each << "joy" << "to" << "the" << "world";

return 0;
}
 
J

Jonathan Turkanis

3doutpost said:
can anyone tell me why this won't compile under vc7.1 but compiled
under vc6?

#include <iostream>

template < class implementor >
class streamTest
{
public:
streamTest ( implementor& srcIn ) :
writer ( srcIn )

In standard C++, ostreams are noncopyable. When implementor is ostream, this is
an error.
{
}

streamTest ( const streamTest& orig ) :
writer ( orig.writer )
{
}

streamTest < std::eek:stream >& operator<< ( std::eek:stream& (
__cdecl *ftor ) ( std::eek:stream& ) )
{
( *ftor ) ( writer );
return *this;
}

template < class optor > streamTest& operator<< ( const optor&
optorA )
{
writer << optorA;
return *this;
}

private:
implementor writer;

You can make this a reference, "implementor& writer," and then your example
works. But be careful about object lifetimes.
};

int main ( int argc, char* argv [] )
{
streamTest < std::eek:stream > each ( std::cout );

each << "joy" << "to" << "the" << "world";

return 0;
}

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top