Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. friend member function can't access private member var?? what's wrong

friend member function can't access private member var?? what's wrong

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ttzzgg_80713
    wrote on last edited by
    #1

    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.

    T C 2 Replies Last reply
    0
    • T ttzzgg_80713

      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.

      T Offline
      T Offline
      ttzzgg_80713
      wrote on last edited by
      #2

      ?

      C 1 Reply Last reply
      0
      • T ttzzgg_80713

        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.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • T ttzzgg_80713

          ?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C Christian Graus

            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

            T Offline
            T Offline
            ttzzgg_80713
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups