Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


simple operator << problem in VC++6.0

This topic is 6542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! I need some help here. I''m learning C++ and use VC++ 6.0 and in the book there is an example. Here is the header file (strng1.h). #ifndef _STRNG1_H_ #define _STRNG1_H_ #include using namespace std; class String { private: char *str; int len public: //some functions... friend ostream &operator <<(ostream &os, const String &st); }; #endif And here is strng1.cpp #include #include "strng1.h" using namespace std; //Some functions... ostream &operator <<(ostream &os, const String &st) { os << st.str; return os; } Now, VC++ gives this error message... Compiling... strng1.cpp d:\devstudio\myprojects\listning 11_1\strng1.cpp(36) : error C2248: ''str'' : cannot access private member declared in class ''String'' d:\devstudio\myprojects\listning 11_1\strng1.h(9) : see declaration of ''str'' vegnyhet.cpp Can you tell me what is wrong? I have seen the same example in another book so I think there is something wrong with VC++. Please tell me how to make this work. Thanx!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
A friend should be able to access private members. I know what the problem is, you are right, VC is to blame!

Before anyone slags me off, I have looked into this! Service Pack 4 for visual studio fixes this problem which only occurs with the << operator.

Hope this helps! (the service pack is a big d/l though)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!