gpt4 book ai didi

c++ - 在函数中使用枚举参数

转载 作者:搜寻专家 更新时间:2023-10-31 01:15:44 27 4
gpt4 key购买 nike

我在 Windows 上工作,使用 C++ 和 Visual Studio。

我有一个类有:

enum algorithmStatus { LOADING, DETECTION, TRACKING, LOST };

在声明中,我想使用 setter 和 getter 来更改状态,例如:

void MyStatusClass::setAlgorithmStatus(algorithmStatus newStatus)
{
//_Status = newStatus;
//_Status = MyStatusClass::algorithmStatus::LOADING;
}

但我无法编译,因为我得到:

Error 5 error C2511: 'void MyStatusClass::setAlgorithmStatus(MyStatusClass::algorithmStatus)' : overloaded member function not found in 'Nft_Status' c:\MyStatusClass.cpp 197

我怎样才能正确地做那个二传手?

编辑:

在 header 中已经声明:

    void setAlgorithmStatus(MyStatusClass::algorithmStatus newStatus);

和:

void setAlgorithmStatus(algorithmStatus newStatus);

在 cpp 中,函数声明只是我写在上面。

已解决

问题是我在构造函数中使用了 MyStatusClass::algorithmStatus,您不需要使用 MyStatusClass::,如果您不需要它,建议不要使用它。

最佳答案

的 MSDN 文档 error code C2511 为您提供了一个值得关注的好 list :

identifier : overloaded member function not found in class

No version of the function is declared with the specified parameters. Possible causes:

  1. Wrong parameters passed to function.
  2. Parameters passed in wrong order.
  3. Incorrect spelling of parameter names.

始终查找错误代码以获得解决编译错误的帮助。

关于c++ - 在函数中使用枚举参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9768013/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com