将#define 和 const 变量相乘时出现 C++ 错误

标签 c++ constants

#include <iostream>
#include<Windows.h>

#define LENGTH 10;
#define NEWLINE '\n'
using namespace std;

int main(){
    int area;
    const int WIDTH=20;
    area=LENGTH*WIDTH;   
    cout<<area<<NEWLINE;
    system("pause");
}

错误在计算面积的那一行,它说“

operand of * must be a pointer

最佳答案

您不应该用 ; 终止宏定义。否则表达式扩展为:

area=10;*WIDTH;

现在这个错误是有道理的,对吧?

关于将#define 和 const 变量相乘时出现 C++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20906590/

相关文章:

c++ - 可变仿函数是否仍然是 "valid"被使用

连接图的 C++ 递归

c++ - 链接到 Visual Studio 2010 中的静态库

c++ - 自动格式化将 >> 更改为 >>

java - 将所有常量放在一个类android中

c++ - 毁灭战士 3 来源 : why does a class representing 2-vectors overload the subscript operator twice?

c++ - 是否所有 C++ 编译器都允许使用 static const int 类成员变量作为数组绑定(bind)?

c++ - 在频域中过滤图像

c# - 二进制转十进制

java - 为什么 final Byte 作为 switch 语句中的 case 不能编译?