what is better?

Discussion in 'C++' started by ankitks@yahoo.com, Nov 30, 2006.

  1. Guest

    hello,
    I have a question regarding how to include classes .
    Assuming I have a class called

    class paraClass
    {
    enum eType { eOne, eTwo, eThree };
    enum cValue = 4;
    static convertToString (int inNumber) { ...}
    static convertToNumber (int inString) { ...}

    }

    now in parent class, which option is better?

    1.
    class newClass : public paraClass
    {
    public:
    int getValue() const { return myValue * cValue; }
    private:
    int myValue;
    }


    2.
    class newClass
    {
    public
    int getValue() const { return myValue * (paraClass::cValue);
    private
    int myValue;
    }
     
    , Nov 30, 2006
    #1
    1. Advertising

  2. Earl Purple Guest

    wrote:
    > hello,
    > I have a question regarding how to include classes .
    > Assuming I have a class called
    >
    > class paraClass
    > {
    > enum eType { eOne, eTwo, eThree };
    > enum cValue = 4;
    > static convertToString (int inNumber) { ...}
    > static convertToNumber (int inString) { ...}
    >
    > }
    >
    > now in parent class, which option is better?
    >
    > 1.
    > class newClass : public paraClass
    > {
    > public:
    > int getValue() const { return myValue * cValue; }
    > private:
    > int myValue;
    > }
    >
    >
    > 2.
    > class newClass
    > {
    > public
    > int getValue() const { return myValue * (paraClass::cValue);
    > private
    > int myValue;
    > }


    Even assuming you modify paraClass to make its members protected
    (rather than private) to give the derived class access (and you'd
    better give it a protected destructor too just in case), in what way is
    a newClass a "type of" paraClass?

    It might depend what you are going to use it all for - are you going to
    use paraClass for meta-programming because it's useful for that (you
    might have another class that has the same names but with different
    definitions. You can pass such classes into templates).

    Generally inheritance should be used to implement a "is a type of"
    design feature and I don't see how that applies above.
     
    Earl Purple, Nov 30, 2006
    #2
    1. Advertising

  3. Guest

    thanks for your answer. problem (which was not obious from example) is
    that I am using paraClass static members/functions lot in my newClass.
    So I thought I will be better of makeing newClass with paretn
    paraClass. May be give me performance advantage, does it?

    also, what is mata-programming?
     
    , Nov 30, 2006
    #3
  4. Daniel T. Guest

    wrote:

    > I have a question regarding how to include classes .
    > Assuming I have a class called
    >
    > class paraClass
    > {
    > enum eType { eOne, eTwo, eThree };
    > enum cValue = 4;
    > static convertToString (int inNumber) { ...}
    > static convertToNumber (int inString) { ...}
    >
    > }


    Dump the above as a class. Make it a namespace instead.

    --
    To send me email, put "sheltie" in the subject.
     
    Daniel T., Nov 30, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dot_net_junky

    Which is better, C# or C++?

    dot_net_junky, Feb 9, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    454
    Tor B├ądshaug
    Feb 14, 2005
  2. Replies:
    0
    Views:
    389
  3. Peter Bencsik
    Replies:
    2
    Views:
    868
  4. Andrew Thompson
    Replies:
    8
    Views:
    161
    Premshree Pillai
    Jun 7, 2005
  5. Replies:
    2
    Views:
    63
    Mark H Harris
    May 13, 2014
Loading...

Share This Page