User forums > Help

Im having problems with headers and cpp files :)

(1/2) > >>

ace4dsl:
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 :

--- Code: ---#include <iostream>
#include <string>

#include "Person.h"

using namespace std;

int main()
{
    Person p("Lebee");


    string s = p.getIsName();
    cout << s;

    return 0;
}


--- End code ---

cpp file :

--- Code: ---#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;
}


--- End code ---

header file:

--- Code: ---#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


--- End code ---

MortenMacFly:

--- Quote from: ace4dsl on July 02, 2009, 08:32:56 am ---it might be the code so il give you the code also:

--- End quote ---
You need to create a project, then add all 3 files (2x *.cpp and 1x *.h) to it and hit compile.

ace4dsl:
that is what i did..

MortenMacFly:

--- Quote from: ace4dsl on July 02, 2009, 08:41:01 am ---that is what i did..

--- End quote ---
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.

ace4dsl:
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,

Navigation

[0] Message Index

[#] Next page

Go to full version