我正在使用clang 3.4.2 ..编译以下代码
#include <stdio.h>
void haa(int& j){
j=1;
}
int main(){
printf("hello\n");
}
这给出了以下错误:
hello.c:3:13: error: expected ')'
void haa(int& j){
^
hello.c:3:9: note: to match this '('
void haa(int& j){
^
hello.c:3:13: error: parameter name omitted
void haa(int& j){
^
hello.c:4:2: error: use of undeclared identifier 'j'
j=1;
^
3 errors generated.
用gcc进行编译不会产生任何错误或警告...有人可以解释为什么会这样吗?
问题是按引用传递(带有引用而不是指针)不是ac,而是c ++功能。
您需要使用C ++编译器(例如g++
或)来编译代码clang++
。更改文件扩展名.cpp
也可以,因为这告诉编译器将其视为c ++。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句