嘿伙计们。看看这段示例代码。
#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;
}我收到以下错误:
1>
1>c:\documents和设置\黑暗幽灵\1>c:\documents\visual studio 2010\projects\first\first\first.cpp(10):error C2144:语法错误:'int‘之前应该有':’
1>c:\documents和设置\黑暗幽灵\1>c:\documents\visual studio 2010\projects\first\first\first.cpp(12):error C2144:语法错误:'void‘之前应该加上':’
1>c:\documents和设置\漆黑幽灵\1>c:\documents\visual studio 2010\projects\first\first\first.cpp(17):error C2144:语法错误:‘==========’之前应该有':‘==========构建:0成功,1失败,0最新,0跳过==========。
发布于 2010-05-19 06:53:35
声明public和private的语法是错误的。与其他语言不同,在C++中应该是
class person{
private:
char name[20];
int age;
public:
void display();……
发布于 2010-05-19 06:53:50
在C++中,private的工作方式如下:
class A
{
private:
void f();
void g();
};注意冒号。
https://stackoverflow.com/questions/2863420
复制相似问题