C++ Function语意学

来源:互联网 发布:科比总决赛数据 编辑:程序博客网 时间:2024/05/16 19:51

#include <IOSTREAM>
using namespace std;
class CBase
{
public:
 void printA()
 {
  cout<<"printA"<<endl;
 }
 virtual void printB()
 {
  cout<<"printB"<<endl;
 }
 static void printC()
 {
  cout << "调用stati printC" << endl;
 }
};

int main()
{
 CBase *pBase = NULL;
 pBase->printA(); //成功调用,类的非静态成员函数,被转换为Cpase_printA(pBase),其调用和普通函数一样,并且为对象共享的,不占用对象存储区。
// pBase->printB(); //失败调用,因为此时不存在对象,就更不会有虚表指针了。而虚函数的调用需要对象的虚表指针。
 pBase->printC(); //成功调用,类的静态成员函数,被转换为CBase_static_printC(),和普通函数一样调用。
 return 0;
}

0 0
原创粉丝点击