#include <iostream>using namespace Std;class date{public:int day,month,year; void init (int,int,int); void Print_ Ymd ();}; void Date::init (int yy, int mm, int dd) {year = yy; month = mm; day = DD;} void Date::p rint_ymd () {std::cout << year << '-' << month << '-' << day << Std::endl;} int main () {Date date1; Date *P1 = &date1; Pointer to Object P1->init (2006, 3, 28); P1->print_ymd (); int *p2; P2 = &date1.year; Pointer to object data member Std::cout << *p2 << Std::endl; void (Date:: * p3) (int,int,int); Pointer to object member function void (Date:: * p4) (); Pointer to object member function P3 = Date::init; P4 = Date::p rint_ymd; (DATE1.*P3) (2006, 4, 8); (DATE1.*P4) (); return 0;}
The error will be when compiling:
35:13:error:invalid use of non-static member function ' void date::init (int, int, int) '
P3 = Date::init;
36:13:error:invalid use of non-static member function ' void Date::p rint_ymd () '
P4 = Date::p rint_ymd;
The p3= date::init will be replaced by:
P3 = &Date::init;
Change P4 = Date::init to:
P4 = &date::p rint_ymd;
Non-static member functions of C + + are not deterministic until they are instantiated, so the two member functions of date are
Can be assigned after the address is specified.
Invalid use of non-static member function ' void date::init (int, int, int) '