class A
{
public:void Foo(int x, int y) { } // 自动地成为内联函数
}
//正确写法:
// 头文件
class A
{
public:
void Foo(int x, int y);
}
// 定义文件
inline void A::Foo(int x, int y){}
//错误写法:
inline void Foo(int x, int y); // inline 仅与函数声明放在一起
void Foo(int x, int y){}
|
#include <stdio.h>
//函数定义为inline即:内联函数
inline char* dbtest(int a) {
return (i % 2 > 0) ? "奇" : "偶";
}
int main()
{
int i = 0;
for (i=1; i < 100; i++) {
printf("i:%d 奇偶性:%s /n", i, dbtest(i));
}
}
|