iostream vs iostream.h -- VC++5 vs VC++6 problem 
Author Message
 iostream vs iostream.h -- VC++5 vs VC++6 problem

The following small test code works both ways in VC++5.0, Borland 5.0
and Borland CBuilder 3.0 but gives the following error when using

When compiled using othe OLD iostream.h there are NO error and the
program runs as

When compiled using the STL version of iostream the following error
results. This does
not happen on VC++5.0, or Borland C++5.0 or Borland CBuilder 3.0. What's

d:\3l\server\main.cpp(28) : error C2248: '_x' : cannot access private
member declared in class 'Test'
        d:\3l\server\main.cpp(21) : see declaration of '_x'
d:\3l\server\main.cpp(36) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.

tstfriend.exe - 2 error(s), 0 warning(s)

Code follows:

// Use old or new library

#ifdef OLD
// Old non-templete io stream library
#include <iostream.h>
// New STL io stream library
#include <iostream>
using namespace std;

class Test {
 // ostream is a friend of Test class so it can access Test's private _x

 friend ostream& operator<< (ostream&, const Test&);

 Test(int x) : _x(x) {}

 int _x;


// Define the << operator for class Test

ostream& operator<< (ostream& os, const Test& t)
 os << "_x=" << t._x;
 return os;


void main(void)
 Test my(10);

 cout << my << endl;


Barton L. Phillips
Applied Technology Resources, Inc.
9045 Corbin Ave. Ste B2
Northridge, CA 91324
Tel: (818)341-5595 Fax: (818)775-1395
Web: http://www.*-*-*.com/

Sun, 18 Mar 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. iosteam vs iostream.h problems in VC++6.0

2. Iostream vs Iostream.h

3. iostreams vs stdio vs win32 API's

4. problem with VC 6 and iostream and friend funcs

5. Help needed on iostream vs. list

6. iostreams w/ VC 5.0 on Alpha NT

7. VC 6 vs VC7 (

8. Fw: <iostream>, <iostream.h>, Visual C++, g++

9. <iostream>, <iostream.h>, Visual C++, g++

10. mixing iostream.h and std::iostream etc...

11. Migration from old iostream to Standard iostream

12. mixing iostream.h and std::iostream etc...


Powered by phpBB® Forum Software