C++新手求救!!!!!

madisonj 2012-04-26 06:31:20
我早vs2011下面编译报错 求救:

error C2065: 'person' : undeclared identifier e:\app\mytest\mytest\main.cpp
error C2146: syntax error : missing ';' before identifier 'TomJack'
error C3861: 'TomJack': identifier not found e:\app\mytest\mytest\main.cpp
error C2065: 'TomJack' : undeclared identifier e:\app\mytest\mytest\main.cpp
error C2228: left of '.information' must have class/struct/union e:\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;
};
...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
madisonj 2012-04-26
  • 打赏
  • 举报
回复
多谢 解决了
hen_hao_ji 2012-04-26
  • 打赏
  • 举报
回复

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

楼主,把这个类定义移到 main()函数前面,就OK了

33,311

社区成员

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

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