链接器错误,未定义对class::class的引用(在我的例子中是Person::Person)

Linker error undefined reference to class::class (Person::Person in my case)

本文关键字:class Person 我的 引用 错误 未定义 链接      更新时间:2023-10-16

当我试图实现我的程序时,我得到一个链接器错误未定义的引用Person::Person。这三个部分如下。我已经修了几个小时了。我知道这可能是我没有看到的简单的东西。但是我在网上找了一下,仍然没有找到我的答案。所以任何帮助都会很感激。

#ifndef PERSON0_H_
#define PERSON0_H_
#include <string>
class Person // class declaration
{
private:
    static const int LIMIT = 25;
    std::string lname;
    char fname[LIMIT];
public:
   Person() {lname = ""; fname[0] = '';}
   Person(const std::string & ln, const char * fn = "Hay you");
   void Show() const;
   void FormalShow() const;
};
#endif
#include <iostream> 
#include <string>
#include "person0.h"

void Person::Show() const
{
 using namespace std;
      std::cout << fname << " " << lname << 'n';
}           
void Person::FormalShow() const
{
 using std::cout;
      std::cout << lname << ", " << fname << 'n';
}


#include <iostream>
#include <string>
#include "person0.h"
int main()
{
using namespace std;
Person one;
Person two("Smythecraft");
Person three("Dimwiddy", "Sam");
one.Show();
cout << endl;
one.FormalShow();
cout << endl;
two.Show();
cout << endl;
two.FormalShow();
cout << endl;
three.Show();
cout << endl;
three.FormalShow();        

cin.get();
cin.get();
return 0;
}

我不是一个真正的c++人,所以术语可能是错误的,但我想说的是

的实现
Person::Person(const std::string & ln, const char * fn)

构造函数缺失