返回信息流遍了个小程序 试验成员函数指针 结果提示报错 是不是vc语法有变化?
#include <iostream>
using namespace std;
class Mammal
{
public:
Mammal(){HowMany ++;cout << "the number of Mammal is "<< HowMany<<endl;}
~Mammal(){HowMany--;cout << "the number of Mammal is "<< HowMany<<endl;}
void Getage() const {cout<< "it's age is " << itsAge<<endl; }
static void GetNum() {cout << "Now the number of Mammal is : "<< HowMany<<endl;}
private:
int itsAge;
static int HowMany;
};
int Mammal::HowMany=0;
int main ()
{
const int MaxNum=3;
void (Mammal::*pget)() const=0;
pget=Mammal::Getage; // 这里提示说要加个&
Mammal a; //提示说 error C2039: 'pget' : is not a member of 'Mammal'
a.pget;
a.GetNum();
return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #16840同步于 2008/11/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
【帮助】成员函数指针 问题
unicornhx
2008/11/28镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
【 在 unicornhx 的大作中提到: 】
: 遍了个小程序 试验成员函数指针 结果提示报错 是不是vc语法有变化?
: #include <iostream>
: using namespace std;
: ...................
#include <iostream>
using namespace std;
class Mammal {
public:
Mammal() {HowMany ++; cout << "the number of Mammal is " << HowMany << endl; }
~Mammal() {HowMany --; cout << "the number of Mammal is " << HowMany << endl;}
void Getage() const {cout << "it's age is " << itsage << endl; }
static void GetNum() {cout << "Now the number of Mammal is : " << HowMany << endl;}
private:
int itsage;
static int HowMany;
};
int Mammal::HowMany = 0;
int main()
{
const int MaxNum = 3;
void (Mammal::*pget)() const = 0;
pget = &Mammal::Getage;
Mammal a;
(a.*pget)();
a.GetNum();
return 0;
}