hi for some reason when i add a header file and use it with cpp files I always always always :'( get those errors:
||=== personTry, Debug ===|
obj\Debug\main.o||In function `main':|
C:\Documents and Settings\Administrator\Desktop\cpp\personTry\main.cpp|10|undefined reference to `Person::Person(std::string)'|
C:\Documents and Settings\Administrator\Desktop\cpp\personTry\main.cpp|13|undefined reference to `Person::getIsName()'|
||=== Build finished: 2 errors, 0 warnings ===|
it might be the code so il give you the code also:
main :
#include <iostream>
#include <string>
#include "Person.h"
using namespace std;
int main()
{
Person p("Lebee");
string s = p.getIsName();
cout << s;
return 0;
}
cpp file :
#include <iostream>
#include <string>
#include "Person.h"
using namespace std;
Person::Person()
{
m_name = "david";
}
Person::Person(string p_name)
{
m_name = p_name;
}
string Person::getIsName()
{
return m_name;
}
header file:
#ifndef PERSON_H_INCLUDED
#define PERSON_H_INCLUDED
#include <string>
class Person
{
public:
Person();
Person(std::string p_name);
std::string getIsName();
private:
std::string m_name;
};
#endif // PERSON_H_INCLUDED
Quote from: ace4dsl on July 02, 2009, 08:32:56 AM
it might be the code so il give you the code also:
You need to create a project, then add all 3 files (2x
*.cpp and 1x
*.h) to it and hit compile.
that is what i did..
Quote from: ace4dsl on July 02, 2009, 08:41:01 AM
that is what i did..
Switch on full compile log, hit re-build and post the log here (see my sig).
Notice: If you have several targets you'll need to enable *all* files for each target in the project options. This will ensure Person.cpp gets compiled and linked what is missing in your case. This is definitely a wrong project setup.
ok mayb eim doing this wrong, lets say i have my main already i want to add a header file what are the best steps to do it to make sure its well linked, thanks in advance,
Quote from: ace4dsl on July 02, 2009, 06:21:09 PM
want to add a header file what are the best steps to do it to make sure its well linked
Header files are not linked at all! Grab yourself a C++ for beginners book and start reading. Topic locked as we are no C/C++ forum.