I am new to C++, and let's say I have two classes: Creature
and Human
:
/* creature.h */
class Creature {
private:
public:
struct emotion {
/* All emotions are percentages */
char joy;
char trust;
char fear;
char surprise;
char sadness;
char disgust;
char anger;
char anticipation;
char love;
};
};
/* human.h */
class Human : Creature {
};
And I have this in my main function in main.cpp
:
Human foo;
My question is: how can I set foo's emotions? I tried this:
foo->emotion.fear = 5;
But GCC gives me this compile error:
error: base operand of '->' has non-pointer type 'Human'
This:
foo.emotion.fear = 5;
Gives:
error: 'struct Creature::emotion' is inaccessible
error: within this context
error: invalid use of 'struct Creature::emotion'
Can anyone help me? Thanks
P.S. No I did not forget the #include
s