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.
本文地址:http://com.8s8s.com/it/it29669.htm