ok i have a class called CBook...some of the code goes like this
after i instantiate an object of CBook named myBook and passed it to the friend function GetName(myBook); it says some memory error...what is wrong...i dont get it...but if i make the function part of the class CBook and call GetName() it works perfectly..is there some different with friend functions...thanksCode:class CBook { public: CBook() {m_Name = new char[10];} void SetName(char* name); ~CBook() { delete [] m_Name; } private: char* m_Name; friend char* GetName(CBook aBook); }; void CBook::SetName(char* name) { delete [] m_Name; m_Name = new char[strlen(name) + 1]; strcpy(m_Name, name); } char* GetName(CBook aBook) { return aBook.m_Name; }



LinkBack URL
About LinkBacks


