C++中创建头文件的方法
时间:12-01
来源:互联网
点击:
创建头文件。(不带形参)
cpp通过类名+::+函数名被头文件链接。注意一定是类名+::!
函数代码放在cpp下的相应的函数名里,而头文件中的只是函数名,只负责提供映射。
animal.cpp
#include "animal.h"
#include
animal::animal()
{
cout<"hello"
void animal::eat ()
{
cout<"shift"
animal.h
//头文件只写函数名,提供链接地址。
#ifndef ANIMAL_H_H
#define ANIMAL_H_H
class animal
{
public:
animal();
void eat();
};
#endif
-------------------------------------------------------------------------------------
如果不创建头文件就要写这么长的代码 可读性很差#include
class animal
{
public:
animal()
{
cout<"animal construct" } ~animal() { cout<"construct animal" } virtual void breath() { cout<"bubble2" } void eat();//把主函数放在类外的方法 }; class fish:public animal { public: fish() { } ~fish() } void breath() { } }; void animal::eat()//函数类型,属于那个类。把一个函数的实现放到类之外。 { } void main() { }
C++头文 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)