C++ 入门 函数调用,函数指针学习小记

来源:互联网 发布:nginx 地址反向代理 编辑:程序博客网 时间:2024/06/03 22:41

C++ offical tutorial structure overlaoding有:

// overloading class constructors#include <iostream>using namespace std;class CRectangle {  int width, height; public:  CRectangle ();  CRectangle (int,int);  int area (void) {return (width*height);}};CRectangle::CRectangle () { width = 5; height = 5;}CRectangle::CRectangle (int a, int b) { width = a; height = b;}int main () { CRectangle rect (3,4); CRectangle rectb; cout << "rect area: " << rect.area() << endl; cout << "rectb area: " << rectb.area() << endl; return 0;}
但是练习时,cout语句写错为:

 cout << "rect area: " << rect.area() << endl; cout << "rectb area: " << rectb.area() << endl;
导致编译时提示:

d:\c++python\learnc++\learnc++\structureoverloading.cpp(27) : error C3867: 'CRectangle::area': function call missing argument list; use '&CRectangle::area' to create a pointer to member

原因: class.fucntion 是调用函数指针, 而class.function()才是函数调用

原创粉丝点击