Class header and implementation in diff files

Hello,

This should be a very basic question, I have my class defination and implementation in two different files, and in my third file I have my main() and I try to make an object of the class. I'm not sure how to link them together. Text book doesn't really show how.

Thanks.
======================================================================
here is my def file - classDef.h

#include<iostream>
#include<string>
using namespace std;

class personType
{

public:
void showAge() const;
void showName() const;
void addAge(int);
void setName(string);
personType();
private:
string name;
int age;

};

=============================================================
here is my implementation file - classImp.cpp

#include "classDef.h"
#include<iostream>
using namespace std;

void personType::showAge() const
{
cout << "age is " << age;
}

void personType::addAge(int myAge)
{
age = myAge;
}


personType::personType()
{

name = "tom";
age = 28;
}

==================================================
here is my main() file



#include<iostream>

#include "classDef.h"

using namespace std;

int main()
{

personType me;
me.showAge();

return 0;
system("PAUSE");
}



I'm using DEV c++ as my compiler.

Thanks!
Last edited on
Don't use Dev-C++, its old, outdated and no longer updated. Try using Code::Blocks, or at the very least wxDev-C++ which is updated. How you link files depends on what compiler your using, but generally your IDE will automatically link all source files in a project. Just create a new project, add your files and compile it. The IDE should pass the source files to be compiled/linked.
Thanks ModShop.
Topic archived. No new replies allowed.