Note that there are some explanatory texts on larger screens.

plurals
  1. POusing reference from abstract class in a child class of abstract class c
    primarykey
    data
    text
    <p>Hullo, first time asking a question! I have 3 classes, CharacterBuilder, which is an abstract class, BullyCharacterBuilder, which inherits from CharacterBuilder and redefines one of its functions, and Character, which is a generic class full of ints with accessors/mutators that I need to use.</p> <p>I define a pointer to Character in CharacterBuilder.h like so:</p> <pre><code> #ifndef CHARACTERBUILDER_H #define CHARACTERBUILDER_H #include "Character.h" class CharacterBuilder { public: Character* getCharacter(); void createNewCharacter(); virtual void buildCharacter(int level) = 0; protected: Character* leeroy; }; #endif </code></pre> <p>CharacterBuilder.cpp</p> <pre><code> #include "CharacterBuilder.h" #include "Character.h" Character* leeroy; Character* CharacterBuilder::getCharacter() { return leeroy; } void CharacterBuilder::createNewCharacter(){ leeroy = new Character; } </code></pre> <p>Then I inherit publicly from CharacterBuilder in my BullyCharacterBuilder class like so:</p> <pre><code>#ifndef BULLYCHARACTERBUILDER_H #define BULLYCHARACTERBUILDER_H #include "Character.h" #include "CharacterBuilder.h" class CharacterBuilder; class BullyCharacterBuilder : public CharacterBuilder{ CharacterBuilder* myParent; void buildCharacter(int level); }; #endif </code></pre> <p>Finally, in the cpp file for my BullyCharacterBuilder, I attempt to call accessor/mutators from the Character pointer (which I assume I've inherited from CharacterBuilder) like so:</p> <pre><code>#include "Character.h" #include "BullyCharacterBuilder.h" #include "CharacterBuilder.h" void buildCharacter(int level){ leeroy-&gt;setAbilityScores(); } </code></pre> <p>When I attempt to do this, I get <strong>Error: identifier "leeroy" is undefined</strong> It might be a dumb question but I tried searching for this particular problem on stackoverflow and google using every combination of keywords I could think of. Would be much obliged to any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload