zoukankan      html  css  js  c++  java
  • c++,内联成员函数

    内联成员函数
    有两程方式实现内联成员函数
    1)在声名成员函数的同时定义成员函数体
    2)声明成员函数时,在最前面加上inline关键字
    在定义成员函数时也在最前面加上inline关键字

    建议inline函数在头文件中声明,以便被不同文件使用。【同c】

    注意:内联函数中如果出现条件或循环语句,则不会被真正当成内联函数来使用

    //app.h
    #include <iostream>
    using namespace std;
    #include <string>
    class Demo 
    {
    public:
        string name ;
        Demo(string str);
        void Demo::show()//在声明成员函数的同时定义成员函数体
        {
            cout<<"name"<<this->name<<endl;
        }
    
    };
    //app.h
    #include <iostream>
    using namespace std;
    #include <string>
    class Demo 
    {
    public:
        string name ;
        Demo(string str);
        inline void show();//声明成员函数时,在最前面加上inline关键字
    };
    
    inline void Demo::show()//在定义成员函数时也在最前面加上inline关键字
    {
        cout<<"name"<<this->name<<endl;
    }
    //app.cpp
    #include <iostream>
    using namespace std;
    #include <string>
    #include "cc.h"
    
    Demo::Demo(string str)
    {
        this->name = str ;
    }
    
    int main()
    {
        Demo demo1("caicai");
        demo1.show();
    
        while(1);
        return 0 ;
    }
  • 相关阅读:
    506. 相对排名 Relative Ranks
    500. 单词是否在键盘上的同一行 Keyboard Row
    openstack live migration性能分析
    libvirt/qemu特性之numa
    nova Scheduling 配置
    Specify compute hosts with SSDs
    nova conductor
    osprofiler
    watcher
    stacktach和ceilometer
  • 原文地址:https://www.cnblogs.com/mylinux/p/4092643.html
Copyright © 2011-2022 走看看