#include <iostream>
using namespace std;
class XY
{
public:
void show() const
{ cout<<"1"<<endl; }
void show()
{ cout<<"2"<<endl; }
};
int main()
{
const XY * const show_1 = NULL;
show_1->show();
XY * show_2 = NULL;
show_2->show();
}
本文通过一个简单的C++程序示例介绍了如何使用常量指针来调用类成员函数。示例中定义了一个名为XY的类,并在其中声明了两个同名但签名不同的show成员函数,分别用于常量指针和非常量指针的调用。
#include <iostream>
using namespace std;
class XY
{
public:
void show() const
{ cout<<"1"<<endl; }
void show()
{ cout<<"2"<<endl; }
};
int main()
{
const XY * const show_1 = NULL;
show_1->show();
XY * show_2 = NULL;
show_2->show();
}

被折叠的 条评论
为什么被折叠?