我有以下方法:
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!
我指定:
- 我已经重建了所有的解决方案
- 全部以Debug方式编译
- Visual Studio 是 2010 年
- setName()的参数名是在调用瞬间,这导致后面抛出异常,本次调试事件的需要源于抛出的异常,为了理解为什么...
最佳答案
我能想象这样的事情会发生的唯一方法是用这样的例子:
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 ;
}
我想你的程序中也发生过类似的事情。
关于c++ - 了解调用堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27440892/