有人可以解释为什么q [0] .data-> f3()不能在类p的函数xyz()中工作。而sa.data-> f3();正在工作,但我在向量中推送相同的对象。我不确定是什么导致了这个问题。在调试GDB时,我在同一行收到此错误:Cannot find bound of current function
#include <iostream>
#include <vector>
using namespace std;
class x{
public:
virtual int f1() = 0;
virtual int f3(){
return 0;
}
};
class y : public x{
public:
virtual int f1(){
return 0;
}
virtual int f3(){
return 1;
}
y(){
cout<< " in y" << endl;
}
};
class z{
public:
int k;
x * data;
z(){
cout << " in z " << endl;
y yy;
data = &yy;
}
};
class p{
public:
vector<z> q;
int xyz(){
cout<< "In XYZ " << endl;
z sa;
cout << sa.data->f3() << endl;
q.push_back(sa);
cout << q[0].data->f3();
}
};
int main(){
p pp;
pp.xyz();
return 0;
}