[英]Understanding the recursive call mechanism for implementing a queue using a stack
[英]Understanding call stack
我有以下方法:
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;
}
通過以下代碼調用:
bsm::MaterialLayer * ml = this->o_bsm_material_layer;
std::string name = ml->getName();
當我在第二行(調用ml-> getName()時)進入調試時,我輸入了以下方法:
void Material::setName(const std::string &name)
{
this->name = name;
}
但是我無法理解為什么它被調用,因為被調用的方法是Material類的setter,而原始調用是在MaterialLayer類的getter上!
我指定:
我可以想象這樣的事情發生的唯一方法是這樣的例子:
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 ;
}
我想你的程序中會發生類似的事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.