正如标题所述.以下代码显示错误:
#include <iostream>
using namespace std;
class link
{
public:
link()
{
num=0;
next=NULL;
}
int num;
link* next;
};
int main() {
link test;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译此代码
g++ test.cpp -o test
Run Code Online (Sandbox Code Playgroud)
我的g ++版本是
g ++(Ubuntu/Linaro 4.6.3-1ubuntu5)4.6.3
编译器显示以下错误
test.cpp: In function ‘int main()’:
test.cpp:18:10: error: expected ‘;’ before ‘test’
Run Code Online (Sandbox Code Playgroud)
如果我评论这个'链接测试'声明,那么一切都好.此外,如果我用'Link'等其他名称替换'link',一切都还可以.
在Visual Studio或VC中,代码没问题....所以它非常困惑我.
最近,我需要声明一个字符串数组,所以我写下了以下语句:
const char** directories = {"cricket_batting", "cricket_bowling", "croquet", "tennis_forehand", "tennis_serve", "volleyball_smash"};
Run Code Online (Sandbox Code Playgroud)
但是,g ++向我显示了错误:
error: scalar object ‘directories’ requires one element in initializer
Run Code Online (Sandbox Code Playgroud)
所以我把声明改为:
const char* directories[] = {"cricket_batting", "cricket_bowling", "croquet", "tennis_forehand", "tennis_serve", "volleyball_smash"};
Run Code Online (Sandbox Code Playgroud)
这一次,这是对的.但我不能确切地知道之间的区别char**和char[].