读书人

C++新手!

发布时间: 2012-04-28 11:49:53 作者: rapoo

C++新手求救!!!!!
我早vs2011下面编译报错 求救:

error C2065: 'person' : undeclared identifiere:\app\mytest\mytest\main.cpp
error C2146: syntax error : missing ';' before identifier 'TomJack'
error C3861: 'TomJack': identifier not founde:\app\mytest\mytest\main.cpp
error C2065: 'TomJack' : undeclared identifiere:\app\mytest\mytest\main.cpp
error C2228: left of '.information' must have class/struct/unione:\app\mytest\mytest\main.cpp
以上是报错代码

以下是程序代码:

#include <iostream>
#include <string>

using namespace std;

void main()
{
string username = "jack";
int age= 21;
int height = 175;
float weight = 55.5;
person TomJack(username,age,height,weight);
TomJack.information();

}
class person
{
public:
person(string n, int age, int height, float weight);
void information();
private:
string name;
int age;
int height;
float weight;
};

person::person(string n, int a, int h, float w)
{
name = n;
age = a;
height = h;
weight = w;
};

void person::information()
{
cout<<age<<endl;
cout<<height<<endl;
cout<<weight<<endl;
cout<<name<<endl;
};


[解决办法]

C/C++ code
class person{public:    person(string n, int age, int height, float weight);    void information();private:    string name;    int age;    int height;    float weight;}; 

读书人网 >C++

热点推荐