"
map<string,armour> char_armour;
char_armour["head"]=a_GetNull;
" ends up producing.
D:\dos\numberstest\surefirewaytodie2.cpp|202|error: 'char_armour' does not name a type|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 1 seconds) ===|
You can download the full code here:
puu.sh/4WDIO.cpp
Just so I can prove that I included the proper headers.
I'm using CodeBlocks.
And yes, "armour" is a class.
But otherwise, how can I declare the various equipment slots to the character?
I tried with pointers, but that would be problematic if I play it "safe" (using private variables, then constructors....)
Your code will work... it just has to go somewhere that code can execute. Class bodies are for declaring things... they are not for executable code.
Move your code somewhere that code can actually run (ie: in a function). In this case... it would be appropriate to move this code to the class's constructor.
char_armour is a pointer which points to a random place in memory. You may not dereference it or index it as if it were an array with a pointer to const char.
Since there is no reason for it to be a pointer, why have you made it a pointer?
[Edit: And one wonders why you aren't attempting to initialize the other 35ish class variables in the constructor. One also wonders at the design that allows 35ish variables in a single class.]
The code is still under construction.
The point is, there is the weapon class. There will be iron swords, steel swords, etc.
And there will be the characters, who will... you know, have those weapons.
There is an object call eq_wpn (equipped weapon), which obviously takes all the variables of a certain weapon....
Then there are armour too, and....
Anyway, the point is, that a friend told me to use maps and dictionaries instead of "the 5000 pointers" (which are most probably troublesome anyway.... I'm not even sure that objects can be even equated)
I recently contacted her that the maps she adviced me are having all sorts of actions, so it would most likely wiser for me to stick to the pointer objects.
Download my code and try to compile it. See the error for yourself.
I replaced the string and the armour-object both with integers, and it worked fine.
So it apparently has problems with me using a string as the key, and an object as the value.
I'm sticking to my 5000+ pointers, even if other programmers call it a "bad practice". A bad practice it may be, it's at least functional.
Unlike the "map" thing a more experienced comrade suggested... What a joke.... what a waste.
I replaced the string and the armour-object both with integers, and it worked fine.
So it apparently has problems with me using a string as the key, and an object as the value.
As I said before, you didn't actually have a map. You had an uninitialized pointer to map.
http://puu.sh/4Y6HW.png
This only happens when I declare the chr and when I have the equipment declared (armour, weapons)
When I remove either, the error does not come up.