I'll get right to the point:
I'm trying to make a game sort of like Dwarf Fortress, but a lot less complex. It's going to be text based, and you'd enter in text commands, and the dwarves would do it. I've never really used classes much, so is there anything wrong with what I have below?
I'm getting an error for my deconstructer function:
23|error: type 'int' argument given to 'delete', expected pointer|
24|error: type 'std::string {aka struct std::basic_string<char>}' argument given to 'delete', expected pointer|
How would I create multiple instances of the class? For example, if I wanted to add a number of dwarves in game, but I wouldn't know how many to create until I was playing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Dwarf
{
public:
int age, Xpos, Ypos, carry;
string job, name;
Dwarf (string n, int a, int x, int y);
~Dwarf ();
string GetName(){return name;}
string GetJob(){return job;}
int GetXpos(){return Xpos;}
int GetYpos(){return Ypos;}
int GetCarry(){return carry;}
};
std::vector<Dwarf> dwarves;
//whenever you want to add another dwarf:
dwarves.push_back(Dwarf("Name", 10, 32, 24));
//in C++11 it is better to use .emplace_back() for this