首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

使用VC++6.0时用#ifdef出错解决思路

2012-03-06 
使用VC++6.0时用#ifdef出错我写了个程序发现用了#ifdef后就编译出错,删了后就行了。请教是怎么回事。是我的

使用VC++6.0时用#ifdef出错
我写了个程序发现用了#ifdef后就编译出错,删了后就行了。请教是怎么回事。是我的编译器有问题吗?使用的是VC++6.0。创建的是Win32 console Application
以下是代码

头文件:
#ifdef PERSONTYPE_H
#define PERSONTYPE_H

#include<string>
using namespace std;

class personType
{
public:
 void print() const;
 void setName(string first,string last);
 void getName(string& ,string& );
 personType(string="",string="");
private:
 string firstName;
 string lastName;
};
#endif




实现文件:
#include"personType.h"

#include<iostream>
#include<string>


using namespace std;

personType::personType(string first,string last)
{
 firstName=first;
 lastName=last;
}


void personType::getName(string& first,string &last)
{
 first=firstName;
 last=lastName;
}


void personType::setName(string first,string last)
{
 firstName=first;
 lastName=last;
}


void personType::print() const
{
 cout<<firstName<<" "<<lastName<<endl;
}




main函数:
#include"personType.h"
#include<iostream>
using namespace std;
int main()
{
 personType person1("dfaff","dsa");
 person1.print();
 return 0;



[解决办法]
应该是#ifndef才继续#define的。
按你写的不是一定要重复包含咯。

热点排行