|
|
C++ Coding Tips - Chapter1 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
C++ Coding TipsBetta Jin< [email protected]> April 15, 2002
Chapter1. Coding Styles
Section1. Let global function body in header file
- The 'inline' keyword:
inline void Hello() { ... } - or - class CHello { public: void SayHello() ; ... } ; inline CHello::SayHello() { ... }
Note: This style let the compiler know that the function should be only once instance ingnoring whether the function can indeed to be inlined, and make the linker happy to link correctly.
- The 'friend static inline' modifier:
// xxx.h #pragma once class CHello { friend static inline void SayHello(CHello * p) { ASSERT(p != 0) ; std::cout << p->m_val ; ... } ... protected: int m_val ; } ; // main.cpp #include "xxx.h" int main() { CHello oHello ; SayHello(&oHello) ; return 0 ; }
Note: Any function modified by friend is global.

|
|
相关文章:相关软件: |
|