内联函数,题号效率,在编译的时候,将代码直接嵌入到调用的地方,
- //Test.h
- # ifndef _TEST_H_
- # define _TEST_H_
- class Test
- {
- public:
- int Add(int a, int b); //内联成员函数
- //{
- //return (a+b);
- //}
- };
- # endif
- //Test.cpp
- # include "Test.h"
- //inline函数的定义
- int Test::Add(int a, int b)
- {
- return (a+b);
- }
- # include "Test.h"
- # include <iostream>
- using namespace std;
- int main(void)
- {
- int res;
- Test t;
- res = t.Add(2,3);
- cout<< "res = " << res << endl;
- return 0;
- }
- //Test.h
- # ifndef _TEST_H_
- # define _TEST_H_
- class Test
- {
- public:
- int Add(int a, int b); //内联成员函数
- {
- return (a+b);
- }
- };
- # endif
















