我仍然在學習C++,並且正在關注我書中的一個例子。我基本上覆制了他們的代碼並添加了包含和名稱空間。我究竟做錯了什麼?鏈接錯誤「ld:fatal:符號引用錯誤。」
代碼:
#include <iostream>
#include <string>
using namespace std;
class Date{
int y,m,d;
public:
Date(int y, int m, int d);
int month(){return m;}
int day(){return d;}
int year(){return y;}
};
int main(){
Date b{1970,12,30};
cout<< b.month()<< '\n';
}
試圖用克來編譯++ -std = C++ 11 -o TEST2 test2.cc
錯誤:
Date::Date(int, int, int) /var/tmp//ccGuivAs.o
ld: fatal: Symbol referencing errors. No output written to main
collect2: ld returned 1 exit status
您需要在某處提供'Date'構造函數的實現。 – blackbird 2014-09-28 14:47:46