2013-03-24 38 views
0

我在尝试实现我的程序时遇到链接器错误,未定义对Person :: Person的引用。以下三部分。我一直在努力修复它几个小时。我知道这可能很简单,我只是没有看到。但我在网上浏览过,仍然没有找到我的答案。所以任何帮助,将不胜感激。链接器错误undefined引用类:: class(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] = '\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; 
} 

回答

4

我不是真的++的人,所以术语可能是错误的是C,但我要说的是,

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

构造函数的实现丢失。

+0

事实证明,剂量不能解决我的问题。如果我放入构造函数,我会得到一个以前定义的错误。 – user2205687 2013-03-25 00:27:03

+0

@ user2205687:你能显示你的实现和错误信息吗? – 2013-03-25 05:51:11

相关问题