what is better?

A

ankitks

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;
}
 
E

Earl Purple

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.
 
A

ankitks

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?
 
D

Daniel T.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top