这段c++代码错误在哪里

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:53:04
#include<iostream>
using namespace std;
class Depet
{
private:
int get;
int out;
public:
void setdata()
{
cin>>get;
cin>>out;
}
void display()
{
cout<<"get="<<get<<endl;
cout<<"out="<<out<<endl;
}
}
Depet dep1,dep2;
int main()
{
dep1.setdata();
dep2.setdata();
dep1.dispaly();
dep2.dispaly();
return 0;
}
F:\c++\lab_2\test.cpp(20) : error C2146: syntax error : missing ';' before identifier 'dep1'
F:\c++\lab_2\test.cpp(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

test.obj - 2 error(s), 0 warning(s)

#include<iostream>

using namespace std;

class Depet
{
private:
int get;
int out;

public:
void setdata()
{
cin>>get;
cin>>out;
}
void display()
{
cout<<"get="<<get<<endl;
cout<<"out="<<out<<endl;
}
}; // 这里需要写 ; 号

Depet dep1, dep2;

int main()
{
dep1.setdata();
dep2.setdata();
dep1.display(); // dep1.dispaly(); 原来你的写法,错误
dep2.display(); // dep2.dispaly(); 原来你的写法,错误

return 0;
}

===>Output:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
Linking...

Cpp1.exe - 0 error(s), 0 warning(s)

认真二字很重要啊
1.类定义后要加分号;
2.display写成dispaly了.

#include<iostream>
using namespace std;
class Depet