关于vc++6.0 Win32 console application下编程问题

//____________People.h#if!defined(AFX_PEOPLE_H__752D0568_87E5_42E4_9263_15222F54E3A0_... //____________People.h
#if !defined(AFX_PEOPLE_H__752D0568_87E5_42E4_9263_15222F54E3A0__INCLUDED_)
#define AFX_PEOPLE_H__752D0568_87E5_42E4_9263_15222F54E3A0__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef People_H
#define People_H
#include<string>
class People
{
private:
string name; //people.h(19)
public:
People(string name); //people.h(21)
void print();
virtual ~People();
};

//___________people.cpp
#include "People.h"
#include <iostream>
#include <string>
using namespace std;
People::People(string name)
{
this.name=name;
}
void People::print()
{
cout<<name<<endl;
}
People::~People()
{
}
#endif
#endif

//_____________Whole.cpp
#include<iostream>
#include<string>
#include "Whole.h"
#include"People.h"
using namespace std;
Whole::Whole()
{
}
Whole::~Whole()
{
}
void main()
{
People p("hello"); //Whole.cpp(20)
p.print();
}
=========错误=========
Compiling...
People.cpp
e:\teststudent\people.h(19) : error C2146: syntax error : missing ';' before identifier 'name'
e:\teststudent\people.h(19) : error C2501: 'string' : missing storage-class or type specifiers
e:\teststudent\people.h(19) : error C2501: 'name' : missing storage-class or type specifiers
e:\teststudent\people.h(21) : error C2629: unexpected 'class People ('
e:\teststudent\people.h(21) : error C2238: unexpected token(s) preceding ';'
e:\teststudent\people.cpp(9) : error C2511: 'People::People' : overloaded member function 'void (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)' not found in 'People'
e:\teststudent\people.h(17) : see declaration of 'People'
e:\teststudent\people.cpp(15) : error C2065: 'name' : undeclared identifier
Whole.cpp
e:\teststudent\people.h(19) : error C2146: syntax error : missing ';' before identifier 'name'
e:\teststudent\people.h(19) : error C2501: 'string' : missing storage-class or type specifiers
e:\teststudent\people.h(19) : error C2501: 'name' : missing storage-class or type specifiers
e:\teststudent\people.h(21) : error C2629: unexpected 'class People ('
e:\teststudent\people.h(21) : error C2238: unexpected token(s) preceding ';'
e:\teststudent\whole.cpp(20) : error C2664: '__thiscall People::People(const class People &)' : cannot convert parameter 1 from 'char [6]' to 'const class People &'
Reason: cannot convert from 'char [6]' to 'const class People'
No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.

testStudent.exe - 13 error(s), 0 warning(s)
================================
貌似是<string>的问题,怎么解决?
创建Whole类只是为了放main函数,第一次用win32ConsoleApplication写,不知道怎么用它?在哪里放main函数?如果要使用多个自定义类,有什么特殊步骤吗?
谢谢指点!
哦,运行出来了,string对象用assign()赋值就行了。
可是还是不知道main函数往哪里写?
而且“每次”修改后的第一次运行都不出结果,修改后第二次运行显示debug无法读取,只能强制结束进程,第三次运行正常,这是什么原因?
展开
 我来答
讨厌熬夜写作业
2012-04-02
知道答主
回答量:9
采纳率:0%
帮助的人:12.9万
展开全部
新建c++ Source file 写main函数。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式