[英]Understanding call stack
I have the following method: 我有以下方法:
std::string MaterialLayer::getName()
{
std::string idfMaterialName = this->material->getName() + std::string("-") + cea::wstring2string(StringConverterHelper::toString((static_cast<double>((floor(this->thickness*1000)) / 10))));
return idfMaterialName;
}
That is called through the following piece of code: 通过以下代码调用:
bsm::MaterialLayer * ml = this->o_bsm_material_layer;
std::string name = ml->getName();
When I do step into debugging on the second line ( where ml->getName() is called ), I entered the following method : 当我在第二行(调用ml-> getName()时)进入调试时,我输入了以下方法:
void Material::setName(const std::string &name)
{
this->name = name;
}
But I cannot understand why it is called given that the called method is a setter on the Material class, while the original call is on a getter of the MaterialLayer class!!! 但是我无法理解为什么它被调用,因为被调用的方法是Material类的setter,而原始调用是在MaterialLayer类的getter上!
I specify that: 我指定:
The only way I can imagine such a thing can happen is with an example like this: 我可以想象这样的事情发生的唯一方法是这样的例子:
class A
{
public:
virtual void FuncA() ;
} ;
class B
{
public:
virtual void FuncB() ;
} ;
void A::FuncA()
{
printf("FuncA\n") ;
}
void B::FuncB()
{
printf("FuncB\n") ;
}
int main()
{
A a ;
B *b ;
b = (B*)&a ;
a.FuncA(); // calls A::FuncA
b->FuncB(); // b points actually to an A object
// calling B::FuncB now actually calls A::FuncA
return 0 ;
}
I suppose a similar thing happend in your program. 我想你的程序中会发生类似的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.