简体   繁体   English

了解调用堆栈

[英]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: 我指定:

  • I have already rebuilt all the solution 我已经重建了所有的解决方案
  • all is compiled in Debug modality all都是在Debug模态下编译的
  • Visual Studio is 2010 Visual Studio是2010年
  • the parameter name of setName() is at the calling instant, this leads to the throwing of an exception later, and the need of this debug activity stemmed from the exception thrown, in order to understand why... setName()的参数名称在调用时刻,这导致稍后抛出异常,并且需要这个调试活动源于抛出的异常,以便理解为什么......

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM