Linker error with constructor

I imagine the solution to this question is really easy but for some reason I can not figure it out.
I keep getting a linker error and I know it has to be the constructor so even with the most basic code left I can't figure out whats wrong.
1
2
3
4
5
6
7
8
9
10
struct Date{
	int y,m,d;
	Date(int m, int d, int y);
};

int main(){
	Date today(12,14,2007);
	keep_window_open();
	return 0;
}

1>datestruc.obj : error LNK2019: unresolved external symbol "public: __thiscall Date::Date(int,int,int)" (??0Date@@QAE@HHH@Z) referenced in function _main

fatal error LNK1120: 1 unresolved externals
You have to define the constructor as well.
1
2
3
4
5
6
7
8
9
struct Date{
	int _y,_m,_d;
	Date(int m, int d, int y)
        {
            _m = m;
            _d = d;
            _y = y;
        }
};
Last edited on
Makes perfect sense, thanks!
If you get an unresolved external, it usually means that you declared a function:
 
int Function(int);

But then forgot to define it:
1
2
3
4
int Function(int i)
{
return i;
}

Usually I get this either when I declare default constructors/destructors, or when I lay out a class and then forget to define a trivial member.
Topic archived. No new replies allowed.