C++ 内联函数

来源:互联网 发布:solidworks软件画足球 编辑:程序博客网 时间:2024/06/01 19:33

使用内臵函数可以节省运行时间,但却增加了目标程序的长度。 因此一般只将规模很小声明为内臵函数。不能使用复杂控制语句,如switch 和while循环

具体实例:

#include <iostream>#include <string>using namespace std;class Student{private:string _name;int _num;public :Student(string str,int num):_name(str),_num(num){}    inline void getValue();};inline void Student::getValue(){cout<<"name :"<<this->_name<<endl<<"num  :"<<this->_num<<endl<<endl;}int main(){Student stu("buyingfei",100);stu.getValue();    return 0;}

运行结果: