PDA

Click to See Complete Forum and Search --> : Polymorphism?


Sam Finch
May 3rd, 2000, 08:27 AM
I want a class that I can use inside another class, but I want it to be a combination of 2 different classes. both would have the same functions but somewhere in the constructor I'd like to specify which one the class is using.
say my 2 classes are



class A
{

public:

A(void);
long Fn(void);

};

A::A(void)
{
}

long A::Fn(void)
{

return 10;

}

class B
{

long m_value;

public:

B(long Value);
long Fn(void);

};

B::B(long Value)
{
m_value = Value;
}

long B::Fn(void)
{

return m_value;

}




Now say I want a class C with an overloaded contructor, if I don't include a value in the constructor it inherits a class A, if I do it inherits a class B.

Is that possible?

May 4th, 2000, 08:36 AM
How about defining two different constructors and depending on which one you use, you can create an instance of the class that is appropriate.
Something like
class C
{
public:
C(void)
{
A a;
}
C(int in)
{
B a;
}
};

Sam Finch
May 4th, 2000, 09:34 AM
Right, I was Kinda Hoping on Inheriting them rather than passing all the properties through(I'm including oversimple examples here) oh well