Error when access struct's member function

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
When run following code, error occur when access struct's member function.

#include <iostream>
#include <vector>
#include <string>
using namespace std;


struct Date {
int d, m, y;
int day() const { return d; };
int month() const;
int year() const;
};
int main()
{
Date x;
x.d = 15;
int y = x.day();
Date* p = &x;
p->m = 7;
int z = p->month();// <=== Error!

return 0;
}

The error occur from following line.

int z = p->month();

Error message is like following.

error LNK2019: unresolved external symbol "public: int __thiscall Date::month(void)const " (?month@Date@@QBEHXZ) referenced in function _main

Can anybody give me any advice?

Continue reading...
 
Back
Top