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. Other Discussions
  3. Clever Code
  4. Tricky One

Tricky One

Scheduled Pinned Locked Moved Clever Code
c++help
11 Posts 9 Posters 5 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.
  • realJSOPR realJSOP

    Given the following:

    class CEDUser
    {
    private:
    long m_nUserID;
    CString m_sName;
    CString m_sDomainLogin;
    COleDateTime m_dtLastLogin;
    long m_nPanelID;
    CString m_sPassword;

    public:
    CEDUser(void);
    virtual ~CEDUser(void);

    long         GetUserID()            { return m\_nUserID;      };
    CString      GetDomainLogin()       { return m\_sDomainLogin; };
    CString      GetName()              { return m\_sName;        };
    CString      GetPassword()          { return m\_sPassword;    );
    COleDateTime GetLastLoginDate()     { return m\_dtLastLogin;  };
    long         GetPanelID()           { return m\_nPanelID;     }; 
    void SetCurrentPanel(long nPanelID) { m\_nPanelID = nPanelID; };
    bool LoadUser(CADODatabase\* pADO, CString sName, bool bLoggingIn);
    bool UpdateUser(CADODatabase\* pADO);
    

    };

    CEDUser::CEDUser(void)
    {
    }

    CEDUser::~CEDUser(void)
    {
    }

    void CEDUser::SetCurrentPanel(long nPanelID) { m_nPanelID = nPanelID; } {}
    bool CEDUser::LoadUser(CADODatabase* pADO, CString sName, bool bLoggingIn) {}
    bool CEDUser::UpdateUser(CADODatabase* pADO) {}

    Find the code that generates the following compiler errors:

    1>c:\eddata\eduser.cpp(5) : error C2535: 'CEDUser::CEDUser(void)' : member function already defined or declared
    1> c:\eddata\eduser.h(17) : see declaration of 'CEDUser::CEDUser'
    1>c:\eddata\eduser.cpp(16) : error C2535: 'CEDUser::~CEDUser(void)' : member function already defined or declared
    1> c:\eddata\eduser.h(18) : see declaration of 'CEDUser::~CEDUser'

    VC6 used to generate truly bizarre error messages when you did the same thing.

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    C Offline
    C Offline
    Chris Meech
    wrote on last edited by
    #2

    It looks like the member function SetCurrentPanel is declared and defined in the header file and then subsequently redefined in the compile file (.cpp I assume). Although this line looks really suspicious

    John Simmons / outlaw programmer wrote:

    void CEDUser::SetCurrentPanel(long nPanelID) { m_nPanelID = nPanelID; } {}

    cause of the double braces?

    Chris Meech I am Canadian. [heard in a local bar] I agree with you that my argument is useless. [Red Stateler] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

    realJSOPR 1 Reply Last reply
    0
    • realJSOPR realJSOP

      Given the following:

      class CEDUser
      {
      private:
      long m_nUserID;
      CString m_sName;
      CString m_sDomainLogin;
      COleDateTime m_dtLastLogin;
      long m_nPanelID;
      CString m_sPassword;

      public:
      CEDUser(void);
      virtual ~CEDUser(void);

      long         GetUserID()            { return m\_nUserID;      };
      CString      GetDomainLogin()       { return m\_sDomainLogin; };
      CString      GetName()              { return m\_sName;        };
      CString      GetPassword()          { return m\_sPassword;    );
      COleDateTime GetLastLoginDate()     { return m\_dtLastLogin;  };
      long         GetPanelID()           { return m\_nPanelID;     }; 
      void SetCurrentPanel(long nPanelID) { m\_nPanelID = nPanelID; };
      bool LoadUser(CADODatabase\* pADO, CString sName, bool bLoggingIn);
      bool UpdateUser(CADODatabase\* pADO);
      

      };

      CEDUser::CEDUser(void)
      {
      }

      CEDUser::~CEDUser(void)
      {
      }

      void CEDUser::SetCurrentPanel(long nPanelID) { m_nPanelID = nPanelID; } {}
      bool CEDUser::LoadUser(CADODatabase* pADO, CString sName, bool bLoggingIn) {}
      bool CEDUser::UpdateUser(CADODatabase* pADO) {}

      Find the code that generates the following compiler errors:

      1>c:\eddata\eduser.cpp(5) : error C2535: 'CEDUser::CEDUser(void)' : member function already defined or declared
      1> c:\eddata\eduser.h(17) : see declaration of 'CEDUser::CEDUser'
      1>c:\eddata\eduser.cpp(16) : error C2535: 'CEDUser::~CEDUser(void)' : member function already defined or declared
      1> c:\eddata\eduser.h(18) : see declaration of 'CEDUser::~CEDUser'

      VC6 used to generate truly bizarre error messages when you did the same thing.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #3

      Is it the following :- CString GetPassword() { return m_sPassword; ); Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

      Regards, Nish


      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
      Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*)

      realJSOPR S B 3 Replies Last reply
      0
      • N Nish Nishant

        Is it the following :- CString GetPassword() { return m_sPassword; ); Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

        Regards, Nish


        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
        Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*)

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #4

        Nishant Sivakumar wrote:

        CString GetPassword() { return m_sPassword; );

        Correct.

        Nishant Sivakumar wrote:

        Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

        I don't know why I do it. Agreed it's not necessary, but I do it anyway.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        L 1 Reply Last reply
        0
        • C Chris Meech

          It looks like the member function SetCurrentPanel is declared and defined in the header file and then subsequently redefined in the compile file (.cpp I assume). Although this line looks really suspicious

          John Simmons / outlaw programmer wrote:

          void CEDUser::SetCurrentPanel(long nPanelID) { m_nPanelID = nPanelID; } {}

          cause of the double braces?

          Chris Meech I am Canadian. [heard in a local bar] I agree with you that my argument is useless. [Red Stateler] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #5

          That was a mistake while typing it into the message. :) Nish found it.

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            Nishant Sivakumar wrote:

            CString GetPassword() { return m_sPassword; );

            Correct.

            Nishant Sivakumar wrote:

            Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

            I don't know why I do it. Agreed it's not necessary, but I do it anyway.

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            John Simmons / outlaw programmer wrote:

            Agreed it's not necessary, but I do it anyway.

            Until recently I would put a semi-colon on the closing brace for a namespace, e.g.:

            namespace rec
            {
            ...
            };

            Until I started playing with PC-Lint, I had no idea that final semi-colon was superfluous.


            Kicking squealing Gucci little piggy.
            The Rob Blog

            M 1 Reply Last reply
            0
            • L Lost User

              John Simmons / outlaw programmer wrote:

              Agreed it's not necessary, but I do it anyway.

              Until recently I would put a semi-colon on the closing brace for a namespace, e.g.:

              namespace rec
              {
              ...
              };

              Until I started playing with PC-Lint, I had no idea that final semi-colon was superfluous.


              Kicking squealing Gucci little piggy.
              The Rob Blog

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #7

              Ah, the joys of symbols with overloaded meanings. {} only needs a following semicolon when it's a type definition:

              struct bob
              {
              int foo;
              char bar;
              };

              You can also declare variables there:

              struct bob
              {
              int foo;
              char bar;
              } baz1, bax2;

              so you need the semicolon to terminate the entire statement. Leaving out that semicolon could cause some really weird behavior back in the old C days, because you could end up with this:

              struct bob
              {
              int foo;
              char bar;
              }

              somefunc(a,b)
              int a; char b;
              { ... }

              If you were expecting the return type of somefunc() to be int implicitly, you'd be wrong because it ends up being bob - yes it was legal to declare a new type right in the middle of a function header. :omg:

              --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

              1 Reply Last reply
              0
              • N Nish Nishant

                Is it the following :- CString GetPassword() { return m_sPassword; ); Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

                Regards, Nish


                Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*)

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #8

                Nishant Sivakumar wrote:

                Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

                I do this myself; I like it. If the function is a simple "getter" or "setter" and inline it makes the class definition more compact and readable.

                Steve

                C 1 Reply Last reply
                0
                • S Stephen Hewitt

                  Nishant Sivakumar wrote:

                  Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

                  I do this myself; I like it. If the function is a simple "getter" or "setter" and inline it makes the class definition more compact and readable.

                  Steve

                  C Offline
                  C Offline
                  Chris S Kaiser
                  wrote on last edited by
                  #9

                  Kinda like putting void in the parameter list for the ctor/dtor.

                  What's in a sig? This statement is false. Build a bridge and get over it. ~ Chris Maunder

                  1 Reply Last reply
                  0
                  • N Nish Nishant

                    Is it the following :- CString GetPassword() { return m_sPassword; ); Also why do you put ; after the {} inline function bodies? It doesn't cause any harm, but certainly an odd habit.

                    Regards, Nish


                    Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                    Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*)

                    B Offline
                    B Offline
                    benjymous
                    wrote on last edited by
                    #10

                    Ouch - yes, I had that happen to me a few weeks ago, yet I didn't spot it here :~ It took quite a bit of head scratching at the time!

                    1 Reply Last reply
                    0
                    • realJSOPR realJSOP

                      Given the following:

                      class CEDUser
                      {
                      private:
                      long m_nUserID;
                      CString m_sName;
                      CString m_sDomainLogin;
                      COleDateTime m_dtLastLogin;
                      long m_nPanelID;
                      CString m_sPassword;

                      public:
                      CEDUser(void);
                      virtual ~CEDUser(void);

                      long         GetUserID()            { return m\_nUserID;      };
                      CString      GetDomainLogin()       { return m\_sDomainLogin; };
                      CString      GetName()              { return m\_sName;        };
                      CString      GetPassword()          { return m\_sPassword;    );
                      COleDateTime GetLastLoginDate()     { return m\_dtLastLogin;  };
                      long         GetPanelID()           { return m\_nPanelID;     }; 
                      void SetCurrentPanel(long nPanelID) { m\_nPanelID = nPanelID; };
                      bool LoadUser(CADODatabase\* pADO, CString sName, bool bLoggingIn);
                      bool UpdateUser(CADODatabase\* pADO);
                      

                      };

                      CEDUser::CEDUser(void)
                      {
                      }

                      CEDUser::~CEDUser(void)
                      {
                      }

                      void CEDUser::SetCurrentPanel(long nPanelID) { m_nPanelID = nPanelID; } {}
                      bool CEDUser::LoadUser(CADODatabase* pADO, CString sName, bool bLoggingIn) {}
                      bool CEDUser::UpdateUser(CADODatabase* pADO) {}

                      Find the code that generates the following compiler errors:

                      1>c:\eddata\eduser.cpp(5) : error C2535: 'CEDUser::CEDUser(void)' : member function already defined or declared
                      1> c:\eddata\eduser.h(17) : see declaration of 'CEDUser::CEDUser'
                      1>c:\eddata\eduser.cpp(16) : error C2535: 'CEDUser::~CEDUser(void)' : member function already defined or declared
                      1> c:\eddata\eduser.h(18) : see declaration of 'CEDUser::~CEDUser'

                      VC6 used to generate truly bizarre error messages when you did the same thing.

                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                      P Offline
                      P Offline
                      peterchen
                      wrote on last edited by
                      #11

                      IIRC you get the same error when you leave ouut the delcaration.


                      Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
                      We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                      Linkify!|Fold With Us!

                      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