当前位置: 代码迷 >> C++ >> VC2008中引用指针有关问题
  详细解决方案

VC2008中引用指针有关问题

热度:4644   发布时间:2013-02-26 00:00:00.0
VC2008中引用指针问题。
#include <iostream>
using namespace std;

class Animal
{
public:
void breathe()
{
cout<<"animal breathe"<<endl;
}
};
class Fish : public Animal
{
public:
void breathe()
{
cout<<"fish bubble"<<endl;
}
};

void fn(Animal *pan)
{
pan->breathe();
}
void main()
{

Fish fh;
Animal *pan;
pan=&fh;
fh(pan);
getchar();
}
红色的一行出现 error C2064: 项不会计算为接受 1 个参数的函数,
我看视频是VC6.0的讲解,在VC2008里面试的。为什么会发生这个问题?如何解决?

------解决方案--------------------------------------------------------
void fn(Animal *pan)
fh(pan);

自己输错了。。。。。。。。
------解决方案--------------------------------------------------------
把函数名改成fn这样就可以编译通过
因为你定义了一个Fish对象fh。而函数名也是fh,所以会出现这个错误。