but i guess i spoke too soon.
anyways, i have not been programming for a while (six years) and this is the first time i am using a container class . . . i wrote a very simple program to test out the vector container:
main.cpp:
----------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
- #include <cstdlib>
- #include <iostream>
- #include <vector>
- #include "fish.cpp"
- using namespace std;
- int main(int argc, char *argv[])
- {
- typedef std::vector<Fish> t_FishVect;
- t_FishVect school(10);
- for(int i = 0; i < 10; i++)
- {
- school[i].setFace(i);
- }
- for(int i = 0; i < 10; i++)
- {
- cout << school[i].getFace();
- }
- cout << "\n";
- system("PAUSE");
- return EXIT_SUCCESS;
- }
fish.cpp:
----------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
- class Fish
- {
- public:
- Fish() {face = 0;}
- Fish(int fishFace) {face = fishFace;}
- ~Fish();
- void setFace(int newFace) {face = newFace;}
- int getFace() {return face;}
- private:
- int face;
- };
everything compiles, but the linker exits with errors:
[Linker error] undefined reference to 'Fish::~Fish()' (x3)
now when i create a container of pointers to Fish it works. but as i understand it, the whole point of containers is to get away from pointers and other such nasties, so i consider a container of pointers to be a failure at an attempt to ease the use of pointers.
as i said, ive never used a container before and im a bit rusty on c++ in general (having not used it for 6 years) so if im missing something simple, please let me know . . . earlier i cut out, saved and then pasted back the exact same portion of code (the Fish class declaration) and it worked. ill try that again, but id rather find a solution that didnt involve my linker being in a good or bad mood.
maybe i just need a different one. i would rather not do that though . . . im using the dev-cpp ide which uses gcc and i like open source.
any help would be greatly appreciated.