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 :
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!!!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.