error C2143: syntax error : missing ';' before '}' 怎么解决

jkr86 2011-10-23 10:04:56
#include<iostream.h>
#include<stdio.h>
class A
{
int x,y;
public:
int z;
A(int xx=0;int yy=0;int zz=0):x(xx),y(yy),z(zz){}
friend void in(A);
friend void sh(A);
};
void in(A a1)
{
cout<<"input x,y:";
cin>>a1.x>>a1.y>>a1.z;
cout<<a1.x<<" "<<a1.y<<" "<<a1.z<<endl;
}
void sh(A)
{
cout<<a1.x<<" "<<a1.y<<" "<<a1.z<<endl;
}
void main()
{
A a1(11,22,33);
sh(a1);
in(a1);
sh(a1);
}
调试的时候经常会有error C2143: syntax error : missing ';' before '}' 这个错误 怎么解决
-------------------Configuration: eg38 - Win32 Debug--------------------
Compiling...
eg38.cpp
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2143: syntax error : missing ')' before ';'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2143: syntax error : missing ')' before ';'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2252: 'yy' : pure specifier can only be specified for functions
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2252: 'zz' : pure specifier can only be specified for functions
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2143: syntax error : missing ';' before ':'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2327: 'A::x' : member from enclosing class is not a type name, static, or enumerator
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2065: 'x' : undeclared identifier
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2065: 'xx' : undeclared identifier
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2057: expected constant expression
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2501: '.alignment member.' : missing storage-class or type specifiers
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2061: syntax error : identifier 'yy'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2040: 'y' : 'int (void)' differs in levels of indirection from 'int'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2061: syntax error : identifier 'zz'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2040: 'z' : 'int (void)' differs in levels of indirection from 'int'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2143: syntax error : missing ';' before '{'
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(8) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
D:\Microsoft Visual Studio\MyProjects\eg38\eg38.cpp(29) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

eg38.obj - 1 error(s), 0 warning(s)
...全文
22725 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序员小迷 2012-02-09
  • 打赏
  • 举报
回复
A(int xx=0;int yy=0;int zz=0):x(xx),y(yy),z(zz){}

应该中间的分号改为逗号;

void sh(A)
改为void sh(A a1)
被窝式覆盖 2011-10-28
  • 打赏
  • 举报
回复
努力学习中
EmilyXiao4 2011-10-25
  • 打赏
  • 举报
回复
我也遇到这种问题了....求答案呀...
d:\haveatry\haveatry.cpp(24) : error C2059: syntax error : ']'
d:\haveatry\haveatry.cpp(24) : error C2143: syntax error : missing ';' before '{'
d:\haveatry\haveatry.cpp(24) : error C2143: syntax error : missing ';' before '}'
d:\haveatry\haveatry.cpp(24) : error C2143: syntax error : missing ';' before ','
d:\haveatry\haveatry.cpp(24) : error C2143: syntax error : missing ';' before ','
d:\haveatry\haveatry.cpp(24) : error C2143: syntax error : missing ';' before ','
d:\haveatry\haveatry.cpp(25) : error C2501: 'S2' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(25) : error C2078: too many initializers
d:\haveatry\haveatry.cpp(26) : error C2501: 'S3' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(26) : error C2078: too many initializers
d:\haveatry\haveatry.cpp(27) : error C2501: 'S4' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(27) : error C2078: too many initializers
d:\haveatry\haveatry.cpp(28) : error C2501: 'S5' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(28) : error C2078: too many initializers
d:\haveatry\haveatry.cpp(29) : error C2501: 'S6' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(29) : error C2078: too many initializers
d:\haveatry\haveatry.cpp(30) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(30) : error C2501: 'cout' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(30) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
d:\haveatry\haveatry.cpp(30) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(31) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(31) : error C2501: 'cout' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(31) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
d:\haveatry\haveatry.cpp(31) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(32) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(32) : error C2501: 'cout' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(32) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
d:\haveatry\haveatry.cpp(32) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(33) : error C2143: syntax error : missing ';' before '>>'
d:\haveatry\haveatry.cpp(33) : error C2501: 'cin' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(33) : error C2371: 'cin' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\istream.h(173) : see declaration of 'cin'
d:\haveatry\haveatry.cpp(33) : error C2143: syntax error : missing ';' before '>>'
d:\haveatry\haveatry.cpp(34) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(34) : error C2501: 'cout' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(34) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
d:\haveatry\haveatry.cpp(34) : error C2143: syntax error : missing ';' before '<<'
d:\haveatry\haveatry.cpp(35) : error C2143: syntax error : missing ';' before '>>'
d:\haveatry\haveatry.cpp(35) : error C2501: 'cin' : missing storage-class or type specifiers
d:\haveatry\haveatry.cpp(35) : error C2371: 'cin' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\istream.h(173) : see declaration of 'cin'
d:\haveatry\haveatry.cpp(35) : error C2143: syntax error : missing ';' before '>>'
d:\haveatry\haveatry.cpp(36) : error C2143: syntax error : missing ';' before 'if'
d:\haveatry\haveatry.cpp(37) : error C2143: syntax error : missing ';' before 'while'
d:\haveatry\haveatry.cpp(38) : error C2143: syntax error : missing ';' before '{'
d:\haveatry\haveatry.cpp(38) : error C2447: missing function header (old-style formal list?)
d:\haveatry\haveatry.cpp(43) : error C2143: syntax error : missing ';' before 'return'
d:\haveatry\haveatry.cpp(44) : error C2143: syntax error : missing ';' before '}'
d:\haveatry\haveatry.cpp(44) : error C2143: syntax error : missing ';' before '}'
d:\haveatry\haveatry.cpp(44) : error C2143: syntax error : missing ';' before '}'
jkr86 2011-10-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 keiy 的回复:]

引用 1 楼 demon__hunter 的回复:
C/C++ code

#include <iostream>
#include <cstdio>
using namespace std;
class A
{
int x,y;
public:
int z;
A(int xx=0,int yy=0,int zz=0):x(xx),y(yy),z(zz){}
friend……
[/Quote]
是VC6 是不是换个版本的好点
柯本 2011-10-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 demon__hunter 的回复:]
C/C++ code

#include <iostream>
#include <cstdio>
using namespace std;
class A
{
int x,y;
public:
int z;
A(int xx=0,int yy=0,int zz=0):x(xx),y(yy),z(zz){}
friend void in(A);……
[/Quote]
程序没问题了
你可能的问题是编译器的问题.
若用vc6的ide,可能要在头上加
#include "stdafx.h"
jkr86 2011-10-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 gfy5216 的回复:]

如果确定不是真的缺少},那可能是当中有特殊的字符或隐藏的空格
[/Quote]


什么意思
jkr86 2011-10-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 demon__hunter 的回复:]

C/C++ code

#include <iostream>
#include <cstdio>
using namespace std;
class A
{
int x,y;
public:
int z;
A(int xx=0,int yy=0,int zz=0):x(xx),y(yy),z(zz){}
friend void in(A);
frie……
[/Quote]




....没用
gfy5216 2011-10-23
  • 打赏
  • 举报
回复
如果确定不是真的缺少},那可能是当中有特殊的字符或隐藏的空格
机智的呆呆 2011-10-23
  • 打赏
  • 举报
回复

#include <iostream>
#include <cstdio>
using namespace std;
class A
{
int x,y;
public:
int z;
A(int xx=0,int yy=0,int zz=0):x(xx),y(yy),z(zz){}
friend void in(A);
friend void sh(A);
};
void in(A a1)
{
cout<<"input x,y:";
cin>>a1.x>>a1.y>>a1.z;
cout<<a1.x<<" "<<a1.y<<" "<<a1.z<<endl;
}
void sh(A a1)
{
cout<<a1.x<<" "<<a1.y<<" "<<a1.z<<endl;
}
int main()
{
A a1(11,22,33);
sh(a1);
in(a1);
sh(a1);
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧