C++ - 错误:"BO3"未在此范围内声明
C++ - error: 'BO3' was not declared in this scope
class BO2Offsets
{
public:
struct Prestige
{
u32 Offset { 0x000000 };
char One { 0x01 },
Two { 0x02 },
Three { 0x03 },
Four { 0x04 },
Five { 0x05 },
Six { 0x06 },
Seven { 0x07 },
Eight { 0x08 },
Nine { 0x09 },
Ten { 0x0A },
MasterPrestige { 0x0B },
CheatedPrestige { 0x0C };
};
};
BO2Offsets BO2;
主.c
BO2 *BO3;
我正在创建一个新元素作为 BO2,但它返回了一个错误:
error: 'BO3' was not declared in this scope
我该如何解决这个问题?
编辑:当我像这样声明 BO3 时:
BO2Offsets *BO3;
我像这样使用 BO3:
BO3->Prestige->Offset
我收到一个错误:错误:无效使用"结构 BO2偏移量::P声望"|
你需要
一个typedef
。您现在拥有的是一个变量声明。
将BO2Offsets BO2;
更改为typedef BO2Offsets BO2;
至于你的第二个问题,你不能使用这样的Prestige
,因为它不是数据成员。如果需要访问内部类型,则需要BO2Offsets::Prestige::Offset
BO2 不是类型,只是变量名,编译器需要类型。
用
BO2Offsets * B03;
编辑:其次用
BO3->Prestige.anyName.Offset;
编辑2;好的伙计们,如果每个人都编辑他的内容,我也编辑:结构引入不当,字段无法访问。现在这样的概念在现代 GCC 上编译正常。顺便说一句,这种引入Prestige
不是太有用,类似于"匿名类"(在某种程度上(。我倾向于在更高级别声明结构/类。在这个片段中可以省略蜜蜂。
但是为字段命名(我的anyName
(对于访问他的内部字段很重要。
class BO2Offsets
{
public:
struct Prestige
{
u32 Offset { 0x000000 };
char One { 0x01 },
Two { 0x02 },
Three { 0x03 },
Four { 0x04 },
Five { 0x05 },
Six { 0x06 },
Seven { 0x07 },
Eight { 0x08 },
Nine { 0x09 },
Ten { 0x0A },
MasterPrestige { 0x0B },
CheatedPrestige { 0x0C };
} anyName; // here !!!
};
BO3 在你的情况下什么都不是。
首先需要铸造 BO3。
BO2Offsets BO3;
或
BO2Offsets *BO3;
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明