[c++] trotz vererbung " not declared in this scope"

Technomagier

Grünschnabel
Hallo, ich bin realtiv frisch in c++ und der dazugehörigen OOP. Und stoße jetzt auf ein paar probleme. Und zwar sagt der Builder mir in den abgeleiteten Klassen, das die Membervariablen und -funktionen der Basisklasse nicht deklariert wären. oO Nun stellt sich mir also die Frage, wo habe ich vergessen, eben jene erreichbar zu machen? Ich benutze als IDE code::blocks, als Compiler den GNU GCC Copiler.


Human.hpp
Code:
#ifndef HUMAN_H_INCLUDE
#define HUMAN_H_INCLUDE


class CHuman
{
protected:
    int n_strength, n_dexterity, n_intelligence, n_toughness;

public:
    CHuman();
    ~CHuman();
    virtual void getAttributes();

};

#endif //HUMAN_H_INCLUDE

Human.cpp
Code:
#include "human.hpp"
#include <iostream>


using namespace std;

/* Konstruktor */
CHuman::CHuman()
{
    n_strength = 10;
    n_dexterity = 10;
    n_intelligence = 10;
    n_toughness = 10;
}

/* Destruktor */
CHuman::~CHuman()
{

}

void CHuman::getAttributes()
{
    cout << "ST = "  << n_strength << endl;
    cout << "GE = "  << n_dexterity << endl;
    cout << "IQ = "  << n_intelligence << endl;
    cout << "KO = "  << n_toughness << endl;
}

Male.hpp
Code:
#ifndef MALE_H_INCLUDE
#define MALE_H_INCLUDE

#include "Human.hpp"

class CMale : public CHuman
{
protected:
    bool gender;

public:
    CMale();
    ~CMale();
    void getAttributes();
};

#endif // MALE_H_INCLUDE

Male.cpp
Code:
#include "Male.hpp"
#include <iostream>
#define MALE false

using namespace std;


CMale::CMale()
{
     gender = MALE; //true = 0 = female, false = 1 = male
}
CMale::~CMale()
{

}

void getAttributes()
{
    cout << "ST = "  << n_strength << endl;
    cout << "GE = "  << n_dexterity << endl;
    cout << "IQ = "  << n_intelligence << endl;
    cout << "KO = "  << n_toughness << endl;
    cout << "Die Person ist maennlich." << endl;
}
 
Guten Morgen,

du hast bei der Definition der "getAttributes" Methode der Klasse "CMale" vergessen, den Klassen-Scope mit anzugeben.

Statt
C++:
void getAttributes()

müsste es
C++:
void CMale::getAttributes()

heissen.

Gruß,
Wolf
 
Zuletzt bearbeitet von einem Moderator:
Zurück