-1

Full error:

error LNK2019: unresolved external symbol "public: int __thiscall Perzon::PrintAge(void)" (?PrintAge@Perzon@@QAEHXZ) referenced in function _main   C:\Users\Srb1313\documents\visual studio 2013\Projects\FirstClass\FirstClass\FirstClass.obj FirstClass

My Folder Structure:

enter image description here

Perzon.h:

  #ifndef Perzon_H
    #define Perzon_H
    #include <iostream>
    #include <string>
    using namespace std;

    class Perzon
    {
    public:
        Perzon();
        Perzon(string firstName, string lastName);

        string PrintName();
        int PrintAge();
    private:
        string mfirstname;
        string mlastname;
        int mage;
    };
    #endif

Person.cpp:

#include "Perzon.h"
#include <string>
using namespace std;

Perzon::Perzon()
{
    mfirstname = "Sammy";
    mlastname = "Bartletty";
    mage = 19;
}

Perzon::Perzon(string firstname, string lastname)
{
    mfirstname = firstname;
    mlastname = lastname;
}

void PrintName(string firtname, string lastname)
{
    cout << "Name is " << firtname << " " << lastname;
}

void PrintAge(int age)
{
    cout << "Age is " << age;
}

FirstClass.cpp:

#include "Perzon.h"
#include <iostream>

int main()
{
    Perzon p("sam", "b");
    p.PrintAge();
};

Can anyone help me here? I have no idea why im getting this error it has had me stumped for so long! Any help is much appreciated.

Srb1313711
  • 2,017
  • 5
  • 24
  • 35

2 Answers2

3

Compiler can't find implementations of your methods because thay are declared outside the class and there is no class specifier for them. In such a situation void PrintAge(int age) declares a global method in global namespace. This can exists simultaneously with void Perzon::PrintAge(int age). Qualify your methods with a class name in the implementation file .cpp:

Perzon::Perzon(string firstname, string lastname)
{
    mfirstname = firstname;
    mlastname = lastname;
}

void Perzon::PrintName(string firtname, string lastname) // change also the
^^^^ ^^^^^^                                              // declaration string
{                                                        // PrintAge();
    cout << "Name is " << firtname << " " << lastname;
}

void Perzon::PrintAge(int age)  // change also the declaration int PrintAge();
^^^^ ^^^^^^
{
    cout << "Age is " << age;
}

A minor suggestion: I am not sure but probably this should be Person since the rest of names is in English.

4pie0
  • 29,204
  • 9
  • 82
  • 118
0

int PrintAge(); - in header.

void PrintAge(int) - in implementation.

The same problem is with Perzon::PrintName()

You have different member function signatures, so it causes an error.

alphashooter
  • 304
  • 1
  • 7