我必须与 С 函数交互,但是此代码无法编译。
// c_enum.h
#pragma once
typedef enum { val1 = 0 } c_style_enum_t;
c_style_enum_t c_func();
// my_class.hpp
#pragma once
extern "С" {
#include "c_enum.h"
}
class my_class {
public:
private:
friend c_style_enum_t ::c_func();
};
Gcc 打印错误:
error: 'enum c_style_enum ' is not a class or namespace
142 | friend c_style_enum ::c_func();
error: ISO C++ forbids declaration of 'c_func' with no type [-fpermissive]
当 c_func() 的返回类型是 int 或除枚举类型之外的其他类型时,此方法有效
如何实现这个功能?