struct references编译错误:期望的标识符或'(''''''''''''''''''''''''

时间:2017-04-21 04:08:34

标签: c++

global

尝试创建对现有结构的引用时,出现以下编译错误: "期望标识符''(''''''''''''''''''''''''#

我错过了什么?

2 个答案:

答案 0 :(得分:3)

您正在使用C编译器而不是C ++编译器进行编译。

C没有引用的概念,因此声明像A_t &BB这样的变量是无效的语法。

如果您正在使用引用,则需要使用C ++编译器进行编译。

答案 1 :(得分:0)

如果您正在编写C ++程序,那么您可以做得很好

struct A_t{
int a;
int b;
};
A_t AA; // You don't need to preceed the struct name with the keyword struct
AA.a = 3;
AA.b = 4;
// your compilation failed in the below step
A_t& BB = AA; // Well, reference to variable (as in &BB) is a functionality of C++.
//If you get an error here, you're probably using a C compiler for a C++ pgm!