Invalid use of non-static member function ' void date::init (int, int, int) '

Source: Internet
Author: User

#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) '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.