找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1727|回复: 1
打印 上一主题 下一主题
收起左侧

c++笔记 创建头文件(不带形参)

[复制链接]
跳转到指定楼层
楼主
ID:104287 发表于 2016-1-31 03:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
创建头文件。(不带形参)
cpp通过类名+::+函数名被头文件链接。注意一定是类名+::!
函数代码放在cpp下的相应的函数名里,而头文件中的只是函数名,只负责提供映射。
animal.cpp
#include "animal.h"
#include <iostream.h>
animal::animal()
{
        cout<<"hello"<<endl;
}
void animal::eat ()
{
  cout<<"shift"<<endl;
}

animal.h
//头文件只写函数名,提供链接地址。
#ifndef ANIMAL_H_H
#define ANIMAL_H_H
class animal
{
public:
        animal();

        void eat();
};
#endif



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:104287 发表于 2016-1-31 03:35 | 只看该作者
        c++ 03 创建头文件前的准备 01
#include<iostream.h>
class animal
{
public:
        animal()
        {
                cout<<"animal construct"<<endl;
        }
        ~animal()
        {
                cout<<"construct animal"<<endl;
        }
        virtual void breath()  
        {
                cout<<"bubble2"<<endl;
        }
        void eat();//把主函数放在类外的方法
};
class fish:public animal
{
public:
        fish()
        {

        }
        ~fish()

        }
        void breath()
        {   
       
        }
};
void animal::eat()//函数类型,属于那个类。把一个函数的实现放到类之外。
{

}

void main()
{

}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表