Visual Studio,错误:在数组声明中使用 #define 常量时,应使用"]"
Visual Studio, Error: expected a ']', when using a #define constant in array declaration
这是我的程序,因为它重现
错误的最小值:
#include <iostream>
#include <Windows.h>
#include <fstream>
using namespace std;
#define iwidth 5;
#define iheight 3;
int main()
{
struct rgb_data_struct {
BYTE B;
BYTE G;
BYTE R;
};
rgb_data_struct **image;
image = new rgb_data_struct *[iwidth];
for (int i = 0; i < iwdith; i++)
{
}
return 0;
}
现在的问题是,当我在主函数中使用 iwdith 时,它用红色之字形线下划线。将鼠标悬停显示"错误:预期为']'"
编译会产生以下错误:
Error 1 error C2143: syntax error : missing ')' before ';' c:usersuser0documentscppbitmapbitmapmain.cpp 51 1 bitmap
Error 2 error C2143: syntax error : missing ']' before ')' c:usersuser0documentscppbitmapbitmapmain.cpp 51 1 bitmap
Error 3 error C2143: syntax error : missing ';' before ')' c:usersuser0documentscppbitmapbitmapmain.cpp 51 1 bitmap
Error 4 error C2143: syntax error : missing ';' before ']' c:usersuser0documentscppbitmapbitmapmain.cpp 51 1 bitmap
Error 5 error C2065: 'iwdith' : undeclared identifier c:usersuser0documentscppbitmapbitmapmain.cpp 52 1 bitmap
6 IntelliSense: expected a ']' c:Usersuser0DocumentsCppbitmapbitmapmain.cpp 51 32 bitmap
7 IntelliSense: expected an expression c:Usersuser0DocumentsCppbitmapbitmapmain.cpp 51 38 bitmap
8 IntelliSense: identifier "iwdith" is undefined c:Usersuser0DocumentsCppbitmapbitmapmain.cpp 52 22 bitmap
我正在使用Microsoft Visual Studio Community 2013。我不明白为什么 IDE 在我声明它时看不到 iwidth!
不要用;
结束你的#define
。这是用预处理器复制下来的。
按原样,iwidth
将被替换为 5;
。去掉宏定义中的分号。
另外,您首先不应该为此使用宏,这不是 C。此外,您似乎在滥用指针。获取更好的C++书籍或教程。
相关文章:
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 什么时候在C++中返回常量引用是个好主意
- 为什么使用类型化的 8 位常量而不是等效的 #define "Impossible constraint"?
- 错误:数字常量 #define BOOT_PROTOCOL 0x00 之前的预期'>'
- 使用常量生成的代码比 #define 小的示例
- C++:在包含的头文件 (Arduino) 中使用 #define 常量
- 为什么我们不能在声明之前使用预处理器 #define 常量
- 使用来自其他方法和 #define 的函数定义常量
- C++ #define 和常量变量相乘时出错
- 如何从预定义常量中获取 #define 符号而不是值
- 循环通过常量枚举#define
- 常量是否比通常使用 #define 更多或更少的内存
- Visual Studio,错误:在数组声明中使用 #define 常量时,应使用"]"
- 定义复常数 "i" C++(#define vs 常量)
- 根据编译时常量,使用相同的标识符 #define 或类型定义是否被认为是可接受的做法?
- 为什么调试器不知道 #define 常量?
- 如何删除#define使用在c++数组常量
- 使用#define声明常量的好处是什么?
- 常量字符串与 #define