gem5 模拟:goodbye.sayGoodbye(myName) 调用时出错

gem5 simulation: error when goodbye.sayGoodbye(myName) calls

我正在学习 gem5 模拟器,我对 C++ 的了解很少,并且我正在遵循 this 教程说明。在构建 object、for goodbye.sayGoodbye(myName); 语句期间,终端显示此错误:

sayGoodbye() 函数内部的定义 GoodbyeObject class :

void
GoodbyeObject::sayGoodbye(std::string other_name)
{
    DPRINTF(Hello, "Saying goodbye to %s\n", other_name);
    message= " Goodbye" + other_name + "!! ";
    fillBuffer();
}

goodbye object 被声明为 const GoodbyeObject * goodbye; 并且 myName 在 class HelloObject 中被声明为 const std::string myName;

我试过 goodbye->sayGoodbye(myName); 而不是 goodbye.sayGoodbye(myName); 并且没有声明再见 object 为常量。这也给出了错误。 能否就此错误发生的原因或我在哪里犯错提供一些见解?

我不熟悉 gem5,但从纯 C++ 的角度来看,您的代码存在多个问题。

  1. 您的 object 是 const 但您的成员函数不是。从变量声明 (GoodbyeObject* goodbye) 中删除 const 或将 const 添加到函数声明 (void GoodbyeObject::sayGoodbye(std::string other_name) const).
  2. 因为你的变量是一个指针,它的成员是用 -> 访问的,而不是 ..
  3. 您的 类型不完整 错误表明您在使用变量之前没有包含 class 定义。如果您转发声明 class(例如 class GoodbyeObject;,请注意末尾的分号)然后尝试使用它而不先完全定义它,就会发生这种情况。您是否包含了定义 GoodbyeObject 的 header?