#include<iostream>
using namespace std;
class date{
public:
int d,m,y;
static date default_date;
public:
date(int dd=0,int mm =0,int yy=0){
d = dd? dd: default_date.d;
m = mm? mm: default_date.m;
y = yy? yy: default_date.y;
}
static void setdefault(int a,int b,int c);
};
void date::setdefault(int a,int b,int c){
default_date = date(a,b,c);
}
int main(){
date xmas;
}
在执行此代码时,vscode显示链接器故障,而在在线ide上执行相同的代码时显示以下错误:
/tmp/ccEXPoPl.o: In function `date::setdefault(int, int, int)':
1f584c669a5ff2377c1509273858b0e8.cpp:(.text+0x3c): undefined reference to `date::default_date'
1f584c669a5ff2377c1509273858b0e8.cpp:(.text+0x45): undefined reference to `date::default_date'
/tmp/ccEXPoPl.o: In function `date::date(int, int, int)':
1f584c669a5ff2377c1509273858b0e8.cpp:(.text._ZN4dateC2Eiii[_ZN4dateC5Eiii]+0x19): undefined reference to `date::default_date'
1f584c669a5ff2377c1509273858b0e8.cpp:(.text._ZN4dateC2Eiii[_ZN4dateC5Eiii]+0x30): undefined reference to `date::default_date'
1f584c669a5ff2377c1509273858b0e8.cpp:(.text._ZN4dateC2Eiii[_ZN4dateC5Eiii]+0x48): undefined reference to `date::default_date'
collect2: error: ld returned 1 exit status
我找不到错误是什么?