Je suis nouveau à C++, et disons que j'ai deux classes: Creature
et Human
:Un struct public à l'intérieur d'une classe
/* 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 {
};
Et je dans ma fonction principale main.cpp
:
Human foo;
Ma question est: comment puis-je définir les émotions de foo? J'ai essayé ceci:
foo->emotion.fear = 5;
Mais GCC me donne cette erreur de compilation:
error: base operand of '->' has non-pointer type 'Human'
Ce:
foo.emotion.fear = 5;
donne:
error: 'struct Creature::emotion' is inaccessible
error: within this context
error: invalid use of 'struct Creature::emotion'
Quelqu'un peut-il me aider? Merci
P.S. Non, je ne l'ai pas oublié le #include
s
"Coilette ta mort me remplit wih douleur, (en colère) colère, (peur) peur, (normal) chaque émotion un acteur peut afficher." - Calculon –