注册 登录
编程论坛 C++教室

为什么全局函数调用结构体变量参数时报出这三个错误

haitao9999 发布于 2009-09-26 12:55, 1157 次点击
Compiling source file(s)...
Sizeof.cpp
Sizeof.cpp:19: error: expected unqualified-id before "return"
Sizeof.cpp:19: error: expected `,' or `;' before "return"
Sizeof.cpp:19: error: expected declaration before '}' token
Sizeof.exe - 3 error(s), 0 warning(s)


源代码如下:(cpp文件独立运行,无头文件)
#include <iostream>
using namespace std;

struct A{
    int  i;
};
void func1(A *a,int j);
void func2(A *a);

int main(){
    A *a ;
    int j = 5;
    func1(a,j);
    func2(a);
   
return 0;
}

return 0;}


void func1(A *a,int j){
    a->i = j;
    cout<<"A->i ="<<a->i<<endl;
}
   
void func2(A *a){
    cout<<"A->i ="<<a->i<<endl;
}
3 回复
#2
debroa7232009-09-26 14:10
return 0;
}
 
return 0;} ??????!!!!!!!!!!!!!!
#3
haitao99992009-09-26 14:26
(代码粘错了,重粘了下)
为什么全局函数调用结构体变量参数时报出这三个错误
 
Compiling source file(s)...
Sizeof.cpp
Sizeof.cpp:19: error: expected unqualified-id before "return"
Sizeof.cpp:19: error: expected `,' or `;' before "return"
Sizeof.cpp:19: error: expected declaration before '}' token
Sizeof.exe - 3 error(s), 0 warning(s)
 
 
源代码如下:(cpp文件独立运行,无头文件)
#include <iostream>
using namespace std;
 
struct A{
    int  i;
};
void func1(A *a,int j);
void func2(A *a);
 
int main(){
    A *a ;
    int j = 5;
    func1(a,j);
    func2(a);
     
return 0;
}
 
 
 
void func1(A *a,int j){
    a->i = j;
    cout<<"A->i ="<<a->i<<endl;
}
     
void func2(A *a){
    cout<<"A->i ="<<a->i<<endl;
}
#4
haitao99992009-09-26 14:30
问题解决了。原来是多写了个return 0;句子。好蠢的错误多亏2楼发现。
1