首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

GCC下引用类型解决思路

2012-02-04 
GCC下引用类型我在VS2005里编写一个程序,现在要转移到Linux的GCC编译。我在VS2005用到了很多引用,但当我用G

GCC下引用类型
我在VS2005里编写一个程序,现在要转移到Linux的GCC编译。我在VS2005用到了很多引用,但当我用GCC编译的时候却提示错误,示例和错误提示如下:
--------------------源程序---------------
#include<stdio.h>
int main()
{
  int a = 10;
  int&x = a;
  printf("Value is %d\n",x);

  return 0;
}
-------------------错误提示-----------------
xxxx@ubuntu:/mnt/hgfs/CCPP$ gcc -c Hello.c
Hello.c: In function ‘main’:
Hello.c:5: error: expected identifier or ‘(’ before ‘&’ token
Hello.c:6: error: ‘x’ undeclared (first use in this function)
Hello.c:6: error: (Each undeclared identifier is reported only once
Hello.c:6: error: for each function it appears in.)

GCC不认识引用'&'吗?还是其他什么原因?希望各位多多指教,谢谢了。O(∩_∩)O~

[解决办法]
引用是C++的内容,把gcc改为g++ 试试
[解决办法]
很容易出问题
[解决办法]
gcc是针对c的,g++可以编译c++

热点排行