gpt4 book ai didi

c++ - 使用枚举

转载 作者:太空狗 更新时间:2023-10-29 21:29:50 25 4
gpt4 key购买 nike

有一个问题我看不懂:

Types.hpp:

enum SomeEnum { one, two, three };

First.hpp:

#include "Types.hpp"
class First
{
public: void someFunc(SomeEnum type) { /* ... */ }
};

第二个.hpp:

#include "Types.hpp"
#include "First.hpp"
class Second
{
public: void Foo()
{
First obj;
obj.someFunc(two); // two is from SomeEnum
}
};

你的错误:

no matching function for call to ‘First::someFunc(SomeEnum)’
note: candidate is: void First::someFunc(First::SomeEnum)

最佳答案

我想你刚刚改变了:

no matching function for call to ‘First::someFunc(SomeEnum)’
note: candidate is: void First::someFunc(First::SomeEnum)

这不是吗:

no matching function for call to ‘First::someFunc(SomeEnum)’
note: candidate is: bool First::someFunc(First::SomeEnum)

无论如何,这改变了一切。枚举是在 class First 中声明的吗?如果是这样,或者如果您不知道,只需尝试调用该函数,将 First:: 放在枚举前面:

obj.someFunc( First::two ); // two is from SomeEnum
^^^^^^^

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

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