I have this assignment that asks me to separate a program into 5 files. The program runs fine as a whole, but when I separated them, I keep getting these two bugs that I can't fix:
@Ganado
There is a vector<Critter> under the class Farm.
@nuderobmonkey
Ok, I will edit my post and I have included vector in farm.h but I ended up getting this error:
/tmp/critFarmTest-368056.o: In function `main':
critFarmTest.cpp:(.text+0x8d): undefined reference to `Critter::GetName[abi:cxx11]() const'
/tmp/farmImp-b2c6e5.o: In function `Farm::RollCall() const':
farmImp.cpp:(.text+0xd9): undefined reference to `Critter::GetName[abi:cxx11]()const'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiler exit status 1
What are you using as a code editor and how are you pasting into the forum? I also can't see what you posted between other < > lines, like your #includes.
If it's saying that vector isn't a template, then that probably means that you don't have #include <vector> in a place that it needs to be. But I can't tell because how ever you're copypasting is getting messed up.
I am using repl.it and I just copied and pasted it from another forum that I had posted my question on. I have used #include <vector> in farm.h, but I am getting this bug:
/tmp/critFarmTest-368056.o: In function `main':
critFarmTest.cpp:(.text+0x8d): undefined reference to `Critter::GetName[abi:cxx11]() const'
/tmp/farmImp-b2c6e5.o: In function `Farm::RollCall() const':
farmImp.cpp:(.text+0xd9): undefined reference to `Critter::GetName[abi:cxx11]()const'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiler exit status 1
Ok, I have gotten rid of it and it still isn't working. Also, all this code is not mine. It is from my book: Beginning C++ Through Game Programming. Thank you guys for the help so far.
When I used 'vector<Critter>::const_iterator iter' instead of 'for (vector::const_iterator iter', the error messages were the same except they now say ./farm.h:16:5: instead of ./farm.h:15:5:
If farm.h is defining a vector of Critters, it needs to know what a Critter is. You need to #include "Critter.h" inside of farm.h. You cannot rely on a forward declaration.
Why don't you paste your latest code into a new post. Of course, use code tags.