我仍然在学习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