Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what is better?

Reply
Thread Tools

what is better?

 
 
ankitks@yahoo.com
Guest
Posts: n/a
 
      11-30-2006
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;
}

 
Reply With Quote
 
 
 
 
Earl Purple
Guest
Posts: n/a
 
      11-30-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
ankitks@yahoo.com
Guest
Posts: n/a
 
      11-30-2006
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?

 
Reply With Quote
 
Daniel T.
Guest
Posts: n/a
 
      11-30-2006
(E-Mail Removed) 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments