请问对象的非虚函数地址在哪,用指针怎么调用?
class Cpersons{
public:
int len;
int max;
Cpersons(){
max=40;
len=0;
p=new Cperson[40];
}
~Cpersons(){
delete[] p;
len=0;
max=0;
}
void out(){ cout<<"out"<<endl;}
}
Cpersons per;
然后直接用指针调用 out; 对象 指针 class
[解决办法]
Cpersons(){
max=40;
len=0;
p=new Cperson[40];
你这样搞还有尽头?
[解决办法]
上面打错了。是:
虚函数在物理上也是在编译是就确定地址,只是不同派生类,虚表的函数指针填充不同的值
[解决办法]
#include<iostream>
using namespace std;
class A{
int x;
public:
A():x(10){};
void print(int n){cout<<"A::print n = "<<n<<", x = "<< x <<endl;};
}
a.print();
//1) push n
//2) lea ecx,a ;//this 指针。
//3) call A::print