friend member function can't access private member var?? what's wrong
-
ifstream & operator >> (ifstream &ifs, const DownKind & d) { ifs >> d.m_strKind >> endl >> d.m_strPath >> endl >> d.m_strSuffix >> d.m_id >> d.m_idParent >> d.m_lstSub.size() >> endl; return ifs; } ofstream & operator << (ofstream &ofs, const DownKind & d) { return ofs; } // class declare #define DOWNKINDBASE DownKindBase class DownKind : public DOWNKINDBASE { public: friend ifstream & operator >> (ifstream &ifs, const DownKind &d); friend ofstream & operator << (ofstream &, const DownKind &); DownKind() ; DownKind(string, string, string, int idParent = -1); virtual ~DownKind() { clear(); } string getKindName(); void setKindName(string); string getPath(); void setPath(string); void setSuffix(string); string getSuffix(); virtual void clone(DownKindBase *); void load(); void save(); virtual void addChild(DownKindBase *); DownKindBase *findByKind(string ); protected: virtual void readFile(FILE *); virtual void writeFile(FILE *); virtual void clear(); virtual void setParentId(int); virtual int getParentId(); private: string m_strKind; string m_strSuffix; string m_strPath; int m_idParent; // parent id int m_id; // current id list m_lstSub; }; could u please tell me what's wrong with this code, don't laught at me.
-
ifstream & operator >> (ifstream &ifs, const DownKind & d) { ifs >> d.m_strKind >> endl >> d.m_strPath >> endl >> d.m_strSuffix >> d.m_id >> d.m_idParent >> d.m_lstSub.size() >> endl; return ifs; } ofstream & operator << (ofstream &ofs, const DownKind & d) { return ofs; } // class declare #define DOWNKINDBASE DownKindBase class DownKind : public DOWNKINDBASE { public: friend ifstream & operator >> (ifstream &ifs, const DownKind &d); friend ofstream & operator << (ofstream &, const DownKind &); DownKind() ; DownKind(string, string, string, int idParent = -1); virtual ~DownKind() { clear(); } string getKindName(); void setKindName(string); string getPath(); void setPath(string); void setSuffix(string); string getSuffix(); virtual void clone(DownKindBase *); void load(); void save(); virtual void addChild(DownKindBase *); DownKindBase *findByKind(string ); protected: virtual void readFile(FILE *); virtual void writeFile(FILE *); virtual void clear(); virtual void setParentId(int); virtual int getParentId(); private: string m_strKind; string m_strSuffix; string m_strPath; int m_idParent; // parent id int m_id; // current id list m_lstSub; }; could u please tell me what's wrong with this code, don't laught at me.
?
-
ifstream & operator >> (ifstream &ifs, const DownKind & d) { ifs >> d.m_strKind >> endl >> d.m_strPath >> endl >> d.m_strSuffix >> d.m_id >> d.m_idParent >> d.m_lstSub.size() >> endl; return ifs; } ofstream & operator << (ofstream &ofs, const DownKind & d) { return ofs; } // class declare #define DOWNKINDBASE DownKindBase class DownKind : public DOWNKINDBASE { public: friend ifstream & operator >> (ifstream &ifs, const DownKind &d); friend ofstream & operator << (ofstream &, const DownKind &); DownKind() ; DownKind(string, string, string, int idParent = -1); virtual ~DownKind() { clear(); } string getKindName(); void setKindName(string); string getPath(); void setPath(string); void setSuffix(string); string getSuffix(); virtual void clone(DownKindBase *); void load(); void save(); virtual void addChild(DownKindBase *); DownKindBase *findByKind(string ); protected: virtual void readFile(FILE *); virtual void writeFile(FILE *); virtual void clear(); virtual void setParentId(int); virtual int getParentId(); private: string m_strKind; string m_strSuffix; string m_strPath; int m_idParent; // parent id int m_id; // current id list m_lstSub; }; could u please tell me what's wrong with this code, don't laught at me.
ttzzgg_80713 wrote: don't laught at me. I would hope that no-one would laugh at you, I've written far worse code than this, I promise you. ttzzgg_80713 wrote: ifs >> d.m_strKind >> endl >> d.m_strPath >> endl >> d.m_strSuffix >> d.m_id >> d.m_idParent >> d.m_lstSub.size() >> endl; You should read my article on iostream inserters and extractors. There is a bit of stuff you should be doing and are not, but the main point here is that you keep using endl, which performs a flush as well as a newline. This is a big performance hit. Also, when I write stuff like this, I have no using statements, I always explcitly scope std:: for everything. The reason is, the code is designed to be included in other projects, and it's probable clients of this inserter will not look at the code, and will silently find stuff pulled into the global namespace. Yes, this is probably just for you ( or your teacher ), but it's good to establish good habits. ttzzgg_80713 wrote: private: You need to make the operator a friend of this class, or provide get methods to get to the data. Again, my article on iostream inserters is the way to go. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
-
and please either fix the email address in your account, or uncheck the setting saying you want to be sent an email copy of replies. It's annoying when they bounce. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
-
ttzzgg_80713 wrote: don't laught at me. I would hope that no-one would laugh at you, I've written far worse code than this, I promise you. ttzzgg_80713 wrote: ifs >> d.m_strKind >> endl >> d.m_strPath >> endl >> d.m_strSuffix >> d.m_id >> d.m_idParent >> d.m_lstSub.size() >> endl; You should read my article on iostream inserters and extractors. There is a bit of stuff you should be doing and are not, but the main point here is that you keep using endl, which performs a flush as well as a newline. This is a big performance hit. Also, when I write stuff like this, I have no using statements, I always explcitly scope std:: for everything. The reason is, the code is designed to be included in other projects, and it's probable clients of this inserter will not look at the code, and will silently find stuff pulled into the global namespace. Yes, this is probably just for you ( or your teacher ), but it's good to establish good habits. ttzzgg_80713 wrote: private: You need to make the operator a friend of this class, or provide get methods to get to the data. Again, my article on iostream inserters is the way to go. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
thanks for u reply, what a kindly person u are !. i has already set operator function to the class's friend. still has problem. and could u tell me where can u find u aritcle??. thank u very much