I seriously suck at programming. Why won't this compile? I don't understand why it thinks it isn't declared within the scope....
I am using..
g++ --std=c++0x main.cpp
My Errors: main.cpp: In function ‘int main(int, char**)’:
main.cpp:136:50: error: template argument 2 is invalid
main.cpp:136:50: error: template argument 4 is invalid
main.cpp:138:9: error: ‘mapConstructor’ was not declared in this scope
I don't know why, but it seems you cannot use std::function<T> as a parameter of a template class/function. Or at least this is what I understood from reading this page:
As far as compiler can distinguish when "*" is a multiplier or when it marks a pointer, it can also understand that >> is to be interpreted as two > > instead of operator >> when > is expected to make template have sense (remember also that in that position operator >> wouldn't have any sense).
So I think is not a real problem.
However the hint could be a nice suggestion in order to have a nicer code to look at :)
Your conclusion is right, I had fallen into my old C++98 ways :)
Your logic is however flawed. A conforming c++98 compiler can tell the difference between a pointer and the multiplication operator, but it still throws a wobbly when you hit it with "vector<vector<int>>"
(remember also that in that position operator >> wouldn't have any sense).
Stuff doesn't compile, for the very reason that it doesn't make sense.
thanks guys! Now I'm getting this error message tho! What in the world does this mean?
g++ --std=c++0x main.cpp /tmp/ccXkVpnY.o: In function `constructItem()':
main.cpp:(.text+0x18): undefined reference to `Item::Item()'
/tmp/ccXkVpnY.o: In function `main::{lambda()#1}::operator()() const':
main.cpp:(.text+0x610): undefined reference to `Item::Item()'
/tmp/ccXkVpnY.o: In function `main::{lambda()#2}::operator()() const':
main.cpp:(.text+0x656): undefined reference to `Weapon::Weapon()'
/tmp/ccXkVpnY.o: In function `main::{lambda()#3}::operator()() const':
main.cpp:(.text+0x69c): undefined reference to `Armor::Armor()'
/tmp/ccXkVpnY.o: In function `main::{lambda()#4}::operator()() const':
main.cpp:(.text+0x6e2): undefined reference to `Creature::Creature()'
collect2: ld returned 1 exit status
like this.. (This is the Item.cpp file) NOTE: This isn't all of the code in the Item.cpp. I was just posting some so you could see how they are parenthesized. Any clue?
The problem is that the command you gave was to try to build an executable. It failed in the link, because it could not find Item.o, etc.. Try adding the -c flag to just compile an object file. Then link all the object files together.