Operator overloading required

I have a class that I derived from CObject...and the strangest thing is happening. There are no dynamic members...yet the compiler insists that I must overload an operator for any operation I want to do with it. Usually....the compiler defaults to a member-by-member copy constructor...however..this one does not. What is different about this class??

class CUserProfile : public CObject

      CUserProfile(CUserProfile* cp);
      virtual ~CUserProfile();
      virtual void Serialize(CArchive& ar);

      //User Profile
      CString m_sFullName;
      CString m_sEMailAddress;
      CString m_sNick;
      CString m_sAltNick;
      CString m_sPassword;
      bool m_bInvisible;
      bool m_bUsePassword;

      //Connection Options
      int m_nRetrys;

      //Display Options
      bool m_bPartJoin;
      bool m_bQuit;
      bool m_bColors;
      bool m_bShowUnknowns;

      //DCC Options
      int m_nPacketSize;
      bool m_bFillFileSpaces;
      bool m_bFastSend;
      bool m_bResume;
      bool m_bWarnAccept;
      CString m_sGetFolder;
      CString m_sSharedFolder;
      bool SetNick(CString n);
      bool SetAlternateNick(CString an);
      void SetRealName(CString rn);
      void SetEmail(CString em);
      void SetPassword(CString p);
      void SetInvisible(bool i);
      void SetRetryCount(int rc);
      void SetShowJoinPart(bool jp);
      void SetShowUnknownMsgs(bool um);
      void SetShowColors(bool sc);
      void SetShowQuits(bool sq);
      void SetPacketSize(int ps);
      void SetFillSpaces(bool fs);
      void SetFastSend(bool fs);
      void SetResumeOnExist(bool roe);
      void SetWarnOnAccept(bool woa);
      void SetGetFolder(CString gf);
      CString GetNick(void);
      CString GetAltNick(void);
      CString GetRealName(void);
      CString GetEmail(void);
      bool GetInvisibleMode(void);
      CString GetPassword(void);
      int GetRetryCount(void);
      bool GetShowJoinPart(void);
      bool GetShowUnknown(void);
      bool GetShowColors(void);
      bool GetShowQuits(void);
      int GetPacketSize(void);
      bool GetFillFileSpaces(void);
      bool GetFastSend(void);
      bool GetResumeOnExist(void);
      bool GetWarnOnAcceptSend(void);
      CString GetSendFolder(void);
      //CUserProfile operator=();
      bool GetUsePassword(void);
      void SetUsePassword(bool up);

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SGyvesAuthor Commented:
For example I can't say obj1 = obj2;
Your variables are all but POD, so you will need both a copy constructor and assignment operator:

CUserProfile::CUserProfile(const CUserProfile& r) {

    m_sFullName=r.m_sFullName ;

    // for all your members....

CUserProfile& CUserProfile::operator=(const CUserProfile& r) {

    m_sFullName=r.m_sFullName ;

    // for all your members....

    return *this;

And, you'll have to declare them like

    CUserProfile(const CUserProfile& r);
    CUserProfile& operator=(const CUserProfile& r);

in your class.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This is from AFX.h

      // Disable the copy constructor and assignment by default so you will get
      //   compiler errors instead of unexpected behaviour if you pass objects
      //   by value or assign objects.
      CObject(const CObject& objectSrc);              // no implementation
      void operator=(const CObject& objectSrc);       // no implementation

So this behaviour is by design.. :)

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

>>So this behaviour is by design.. :)

You are right, but it does not say one can't override it :o)
SGyvesAuthor Commented:
Ok...just wondering why this object suddenly started making me overload assignment and copy. Thank you for the explanation.  :)
>>just wondering why this object suddenly started making me overload assignment and cop

It became too complex for the compiler to handle - and, I actually would recommend implementing these *always*, as a matter of "taste" :o)
SGyvesAuthor Commented:
Yes...yes...I know...it is proper practice to always overload the copy and assignment. Ahhh...so hard not to be lazy. I agree though.
I did not say you cannot override it either! SGyves was wondering why CObject would force him to write an overloaded = operator and tried to answer to the point.
SGyvesAuthor Commented:
I understood Priyesh....no worries.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.