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. abstract base class

abstract base class

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comtoolstutorial
7 Posts 3 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
    toxcct
    wrote on last edited by
    #1

    hello everyone, i have a simple inheritence question for anybody knows... let's take an example. I have the following class definition :

    class CVCalcParserException {
    protected:
    int m_iExceptionNumber;
    std::string m_strExceptionMsg;
    int m_iErrorPos;

    public:
    CVCalcParserException(int iExceptionNumber,
    const std::string& strExceptionMsg,
    int iErrorPos);
    virtual ~CVCalcParserException();
    int GetExceptionNumber();
    std::string GetMessage();
    int GetErrorPos();
    };

    In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as CVCalcParserException.is supposed to provide some services to the derived classes. How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0). any idea ?


    TOXCCT >>> GEII power
    [toxcct][VisualCalc]

    S K 2 Replies Last reply
    0
    • T toxcct

      hello everyone, i have a simple inheritence question for anybody knows... let's take an example. I have the following class definition :

      class CVCalcParserException {
      protected:
      int m_iExceptionNumber;
      std::string m_strExceptionMsg;
      int m_iErrorPos;

      public:
      CVCalcParserException(int iExceptionNumber,
      const std::string& strExceptionMsg,
      int iErrorPos);
      virtual ~CVCalcParserException();
      int GetExceptionNumber();
      std::string GetMessage();
      int GetErrorPos();
      };

      In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as CVCalcParserException.is supposed to provide some services to the derived classes. How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0). any idea ?


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Declare the constructor as protected.

      class CVCalcParserException {
      ...
      protected:
      CVCalcParserException(int iExceptionNumber,
      const std::string& strExceptionMsg,
      int iErrorPos);

      Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      T 2 Replies Last reply
      0
      • T toxcct

        hello everyone, i have a simple inheritence question for anybody knows... let's take an example. I have the following class definition :

        class CVCalcParserException {
        protected:
        int m_iExceptionNumber;
        std::string m_strExceptionMsg;
        int m_iErrorPos;

        public:
        CVCalcParserException(int iExceptionNumber,
        const std::string& strExceptionMsg,
        int iErrorPos);
        virtual ~CVCalcParserException();
        int GetExceptionNumber();
        std::string GetMessage();
        int GetErrorPos();
        };

        In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as CVCalcParserException.is supposed to provide some services to the derived classes. How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0). any idea ?


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        K Offline
        K Offline
        karmendra_js
        wrote on last edited by
        #3

        How about making the constructor protected. If you do that it will be accessed only in derived class. Note: I never tried to do so. Why do you try and let me know too. Regards

        1 Reply Last reply
        0
        • S S Senthil Kumar

          Declare the constructor as protected.

          class CVCalcParserException {
          ...
          protected:
          CVCalcParserException(int iExceptionNumber,
          const std::string& strExceptionMsg,
          int iErrorPos);

          Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          S. Senthil Kumar wrote:

          Declare the constructor as protected

          hum, yeah, i thought to this, but wasn't sure... thank you ;)


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          1 Reply Last reply
          0
          • S S Senthil Kumar

            Declare the constructor as protected.

            class CVCalcParserException {
            ...
            protected:
            CVCalcParserException(int iExceptionNumber,
            const std::string& strExceptionMsg,
            int iErrorPos);

            Regards Senthil _____________________________ My Blog | My Articles | WinMacro

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

            tell me one more thing, i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters. should i also explicitely define this constructor protected ?


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            S 1 Reply Last reply
            0
            • T toxcct

              tell me one more thing, i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters. should i also explicitely define this constructor protected ?


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              S Offline
              S Offline
              S Senthil Kumar
              wrote on last edited by
              #6

              toxcct wrote:

              i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.

              It doesn't. Explicitly defining a constructor suppresses generation of the compiler generated one, so no, you don't need to define the parameterless constructor. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

              T 1 Reply Last reply
              0
              • S S Senthil Kumar

                toxcct wrote:

                i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.

                It doesn't. Explicitly defining a constructor suppresses generation of the compiler generated one, so no, you don't need to define the parameterless constructor. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                ok, thanks a lot... :rose:


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                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