1

This is my code, I am facing problem while build and run.

LNK 2019 Unresolved external symbol error it is.

Please help me to solve this problem.

Person.h

#pragma once
#include<string>
class Person
{
private:
    std::string firstname;
    std::string lastname;
    int age;
public:
    Person();
    Person(std::string fname, std::string lname);
    Person(std::string fname, std::string lname, int age);
    ~Person();
    void setfirstname(std::string fname);
    std::string getfirstname();
    void setlastname(std::string lname);
    std::string getlastname();
    void setage(int age);
    int getage();
    void sayhello();
};

Person.cpp

#include "Person.h"

#include"stdafx.h"

#include<iostream>
Person::Person()
{
    firstname = "";
    lastname = "";
    age = 0;
}
Person::Person(std::string fname, std::string lname)
{
firstname = fname;
lastname = lname;
}

Person::Person(std::string fname, std::string lname, int age)
{
firstname = fname;
lastname = lname;
this->age = age;
}


Person::~Person()
{

}
void Person::setfirstname(std::string fname)
{
this->firstname = fname;
}
void Person::setlastname(std::string lname)
{
this->lastname = lname;
}
void Person::setage(int age)
{
if (age > 0)
{
    this->age = age;
}
else
{
    std::cout << "Plz Enter a valid age" << std::endl;
}
}
std::string Person::getfirstname()
{
return this->firstname;

}
std::string Person::getlastname()
{
 return this->lastname;
}
int Person::getage()
{
return this->age;
}
void Person::sayhello()
{
std::cout << "Hello" << std::endl;
}

Main Function

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

#include"Person.h"


int main()
{
Person *p = new Person("Barry", "Allen", 30);

std::cout << "The name of Person is" << p->getfirstname() << " " << 
p>getlastname() << "  And the age is" << p->getage() << std::endl;
p->sayhello();

return 0;
}

The message I am getting is :

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __thiscall Person::Person(class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator >,int)" (??0Person@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0H@Z) referenced in function _main ConsoleApplication2 C:\Users\Subhajyoti-PC\source\repos\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.obj 1

Kerberos
  • 4,036
  • 3
  • 36
  • 55

0 Answers0