About #include 's

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

  • Moved to general C/C++ since this has nothing to do with game programming.

    It is impossible to say what's causing your problem, please post the code.
  • : 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.
    :

    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
  • : 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.
    :
    [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]
  • It is indeed a serious design flaw, it is entirely against the concept of object orientation. Same goes for pointers to derived classes.

    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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories