hello all
I have a base class defined in one header file and I have a derived class.
the derived class is derived from the base abstract class. In abstract class I want to define a variable of the type of the derived class, but this causes to the name od the derived class in the base class become unknown. How should I do this without getting these errors.
thanks.
Comments
It is impossible to say what's causing your problem, please post the code.
:
: I have a base class defined in one header file and I have a derived
: class.
: the derived class is derived from the base abstract class. In
: abstract class I want to define a variable of the type of the
: derived class, but this causes to the name od the derived class in
: the base class become unknown. How should I do this without getting
: these errors.
:
: thanks.
:
If you're doing what I think you're doing:
[code]
class CBase
{
public:
Something();
private:
CDerived derived;
}
class CDerived : public CBase
{
}
[/code]
Then you have an impossible construction which means you have a serious design flaw in your objects.
But anyway, post the code like Lundin said and we'll know for sure.
Best Regards,
Richard
The way I see it... Well, it's all pretty blurry
: [code]:
: class CBase
: {
: public:
: Something();
:
: private:
: CDerived derived;
: }
:
: class CDerived : public CBase
: {
: }
: [/code]:
: Then you have an impossible construction which means you have a
: serious design flaw in your objects.
:
: But anyway, post the code like Lundin said and we'll know for sure.
:
[color=Blue]This is a design flaw.
However, you can do it by using a pointer to derived class:[/color]
[code]
: class CDerived;
:
: class CBase
: {
: public:
: Something();
:
: private:
: CDerived* pDerived;
: }
:
: class CDerived : public CBase
: {
: }
[/code]
The base class shouldn't know that something has been derived from it. It is as if every manufacturer of "veichles" would build in air bags in their construction, no matter if they are building cars, airplanes, bicycles or moon landers.