I am learning C++ and I am trying to link files together. I know in general how files are linked (did it for a Unix class) but I've noticed that when data structures are introduced, it makes things a lot more difficult. For the life of me, I cannot figure out how to split the program (below) into three files: main.cpp, expand.cpp, and expand.h
The program below is the working program in one file. When I split it up into modules, I get all sorts of access violations and the blue screen of death. I have the two source files in /MyProjects, and the header in /Include (I've also tried keeping it in /MyProjects).
I use Dev C++ and Windows. Any guidance would be appreciated.
#include <iostream>
#include <list>
#include <cstdlib>
using namespace std;
class resources {
private:
float fertility;
public:
float GetFertility() { return fertility; }
void SetFertility( float f ) { fertility = f; }
};
class terrain {
private:
int terrain_type;
public:
int GetTerrain() { return terrain_type; }
void SetTerrain( int t ) { terrain_type = t; }
};
class world : public resources, terrain {
private:
int x, y;
public:
int Getx() { return x; }
int Gety() { return y; }
void Setxy( int a, int b ) { x = a; y = b; }
};
void ExpandMap( list<world> &ob )
{
list<world>::iterator p;
p = ob.begin();
p->Setxy(2,3);
cout << "X and Y: " << p->Getx() << ' ' << p->Gety() << endl;
}
int main()
{
list<world> map;
list<world>::iterator p;
map.push_back();
ExpandMap( map );
p = map.begin();
cout << "\n\nMAIN: X and Y: " << p->Getx() << ' ' << p->Gety() << endl;
system("PAUSE");
return 0;
}