未声明的枚举错误 [英] Undeclared enumeration error

查看:162
本文介绍了未声明的枚举错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在包含之后声明了这样的错误''LETTERS'' undeclared (first use in this function). LETTERS:

Hello, I get this error ''LETTERS'' undeclared (first use in this function). LETTERS in declared after the includes like this:

enum LETTERS{
A = 0,B = 1,C = 2,D = 3,E = 4
}


然后在主要的空白中,我得到那个烦人的错误:


then in the main void I get that annoying error:

int main(void) {
        int Word[] = {LETTERS.A,LETTERS.C,LETTERS.E};
    }
}


如何摆脱这个错误?

注意:这发生在AVR Studio 5


How can I get rid of this error?

Note:This happens in AVR Studio 5

推荐答案

LETTERS是类型名,而不是结构的实例中.如果要引用结构化类型的元素,则需要像这样使用范围解引用运算符''::'':
LETTERS is a typename, not an instance of a struct. If you want to refer to elements of a structured type, you need to use the scope dereferencing operator ''::'' like this:
LETTERS::A


使用
int Word[] = {A,C,E};




->首先,您的Enum声明应以分号结尾.
->由于枚举类型用于设置命名整数常量,因此无法像使用struct或class一样使用点运算符访问其成员.
->因此,可以通过直接使用其成员来像#define-d常量一样使用它们.

例如:int nVar = A;
Hi,

-> First of all your Enum declaration should end with a semicolon.
-> Since enum type is used to set up named integer constants,you cant access its members with dot operator like you do with struct or class.
-> So you can use them like a #define-d constants by using its members directly.

example: int nVar = A;


这篇关于未声明的枚举错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆