Hello,
i where making a game, and i needed a vector that holds class objects, i do the thing (below), and i thing i did it right, but it seems not and i dont know whats wrong :(
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Races {
public:
string raceName;
Races(string get_raceName);
};
vector<Races*> race_list;
Races::Races(string get_raceName) {
raceName = get_raceName;
race_list.push_back(this);
}
Races vampire("Vampire");
Races orc("Orc");
Races elf("Elf");
int main() {
Races* theRace;
int listNumber;
for (int member = 0; member < race_list.size(); ++member) {
theRace = race_list[member];
cout<< listNumber << ". " << theRace.raceName << endl;
++listNumber;
}
}
this code generates error: request for member 'raceName' in 'theRace', which is of non-class type 'Races*'
i would be greatful if someone tell me whats wrong ;)