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;
}
事實證明,劑量不能解決我的問題。如果我放入構造函數,我會得到一個以前定義的錯誤。 – user2205687 2013-03-25 00:27:03
@ user2205687:你能顯示你的實現和錯誤信息嗎? – 2013-03-25 05:51:11