大家好.看看这段示例代码.
#include "stdafx.h"
#include<conio.h>
#include<string.h>
class person{
private char name[20];
private int age;
public void setValues(char n[],int a)
{
strcpy(this->name,n);
this->age=a;
}
public void display()
{
printf("\nName = %s",name);
printf("\nAge = %d",age);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
person p;
p.setValues("ram",20);
p.display();
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
1> ------ Build build:项目:首先,配置:调试Win32 ------ 1> first.cpp 1> c:\ documents and settings\dark wraith\my documents\visual studio 2010\projects\first\first\first.cpp(9):错误C2144:语法错误:'char'前面应加':'
1> c:\ documents and settings\dark wraith\my documents\visual studio 2010\projects\first\first\first.cpp(10):error C2144:语法错误:'int'前面应加':'
1> c:\ documents and settings\dark wraith\my documents\visual studio 2010\projects\first\first\first.cpp(12):error C2144:语法错误:'void'前面应加':'
1> c:\ documents and settings\dark wraith\my documents\visual studio 2010\projects\first\first\first.cpp(17):error C2144:语法错误:'void'前面应加':'== ========构建:0成功,1失败,0最新,0跳过==========
Nav*_*een 11
声明的语法public和private是错误的.与其他语言不同,在C++中它应该是
class person{
private:
char name[20];
int age;
public:
void display();
Run Code Online (Sandbox Code Playgroud)
....
| 归档时间: |
|
| 查看次数: |
2647 次 |
| 最近记录: |