c++ - Visual Studio,在数组声明中使用#define 常量时出现错误 : expected a ']' ,

标签 c++ visual-c++ visual-studio-2013

这是我的程序,因为它重现了错误:

#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;
}

现在的问题是我在 main 函数中使用 iwdith 的地方,它用红色锯齿线加下划线。将鼠标悬停在屏幕上说“错误:需要一个 ']'”

编译产生这些错误:

Error   1   error C2143: syntax error : missing ')' before ';'  c:\users\user0\documents\cpp\bitmap\bitmap\main.cpp 51  1   bitmap
Error   2   error C2143: syntax error : missing ']' before ')'  c:\users\user0\documents\cpp\bitmap\bitmap\main.cpp 51  1   bitmap
Error   3   error C2143: syntax error : missing ';' before ')'  c:\users\user0\documents\cpp\bitmap\bitmap\main.cpp 51  1   bitmap
Error   4   error C2143: syntax error : missing ';' before ']'  c:\users\user0\documents\cpp\bitmap\bitmap\main.cpp 51  1   bitmap
Error   5   error C2065: 'iwdith' : undeclared identifier   c:\users\user0\documents\cpp\bitmap\bitmap\main.cpp 52  1   bitmap
    6   IntelliSense: expected a ']'    c:\Users\user0\Documents\Cpp\bitmap\bitmap\main.cpp 51  32  bitmap
    7   IntelliSense: expected an expression    c:\Users\user0\Documents\Cpp\bitmap\bitmap\main.cpp 51  38  bitmap
    8   IntelliSense: identifier "iwdith" is undefined  c:\Users\user0\Documents\Cpp\bitmap\bitmap\main.cpp 52  22  bitmap

我正在使用 Microsoft Visual Studio Community 2013。我不明白为什么在我声明 iwidth 时 IDE 看不到它!

最佳答案

不要以 ; 结束你的 #define。这是用预处理器复制下来的。

关于c++ - Visual Studio,在数组声明中使用#define 常量时出现错误 : expected a ']' ,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866572/

相关文章:

c++ - 延迟函数调用中的延迟函数调用

c++ - 不明确的访问

c++ - 使用 importlib 属性时的 MIDL2015 警告

c# - Visual Studio 图形调试器忽略工作像素着色器

c++ - 如何确保在 notify_one 之前调用 wait_for

c++ - 在 for 循环中使用 end() 时无法访问双向链表中的最后一个元素

c++ - VirtualAlloc 在某些硬盘配置上失败

c++ - 为什么不使用 #define 来隐藏 unique_ptr 丑陋在这里工作?

c++ - 如何为我的 visual studio 2010 c++ 应用程序制作自动更新程序?

visual-studio-2012 - 无法从文本 '..\Images\Medium.png 创建 imageSource