这里是我的代码:C++结构宣言和使用编译器错误
#include <iostream>
using namespace std;
struct product {
int weight;
float price;
} apple, banana, melon; // can I declare like this ?????
int main()
{
apple a;
}
当我编译此示例中,编译器说:
struct.cpp|11|error: expected ';' before 'a'|
同样的事情在C语言中工作正常...
怎么了?
忽略头文件和命名空间中的C++语法(不需要用al来重现问题这里最简单的代码),代码也不会在C中编译。虽然C和C++是不同的语言,但它们至少是相似的。 – 2011-05-29 14:48:02