error: statement cannot resolve address of overloaded function C++

error: statement cannot resolve address of overloaded function C++

我正在通过书本学习 C++,并试图测试循环游戏战斗的简单编码。 while 循环中的一个开关。

damage = greatsword[0] + player[1] - enemy[2]; endl;

error: statement cannot resolve address of overloaded function|

我在 4 个不同的代码行中有这个错误,并且在每个代码行中都有 'damage' 所以我认为它有一些问题。在尝试将其更改为攻击值之前,我将损坏声明为 int 并设置为 0。如果需要,我可以提供更多代码。我还尝试将名称从 x 更改为 dmg 以查看是否是问题所在

您有一个尾随 endl;,您可能并不打算包括在内。 std::endl 是打印到输出流时使用的函数;通常你会看到 cout << ... << endl;,否则不应使用它。

std::endl,用作流操纵器,实际上是一个函数。

您这样做可能会得到类似或相关的错误消息

 void f();   // don't need to define f()

 int main()
 {
      f;    //   should be f() to call the function
 }

所以去掉语句endl;