|
发表于 2004-9-8 21:17:21
|
显示全部楼层
Agree with 无双,JBug,and lucifer.
U should put inline functions' definations in header files.
Two form:
1. member funcions defined inside class body are auto inline, but whether they are really inlined depend on compiler.- /* person.h */
- class Person
- {
- int m_age;
- public:
- ...
- int getAge() { return m_age; } // [color=red]defination after declaration,implicit,"inline" keyword not need[/color]
- }
复制代码
2. member functions declared in class body, but defined outside class body can be inlined by prefixing "inline" keyword. - /* person.h */
- class Person
- {
- int m_age;
- public:
- ...
- inline int getAge(); // declaration,explicit
- };
- // [color=red]also in persion.h[/color]
- inline int
- Person::getAge() { return m_age; } // defination
复制代码 |
|