对inline函数使用单独的定义文件
2009-10-21 23:22
267 查看
为了提高效率,类中的一些帮助器函数经常使用
inline
,为了清晰的分别哪些是
inlie
的函数,哪些不是,则可以使用这样一种方法:用单独的文件存放
inline
函数。
在
cegui
的
silly
库的实现中,所有用到的
inlie
函数都被放在相应
.h
文件对应的
.icpp
文件中,比如:
SILLYDataSource.h
//
有这样的
inline
定义文件存在
SILLYDataSource.icpp
而在对应的
SILLYDataSource.cpp
中,这样处理:
#ifndef SILLY_OPT_INLINE
#define inline
#include "SILLYDataSource.icpp"
#undef inline
#endif
这个似乎有些多余,基本上在具体的实现文中,只要包含
SILLYDataSource.icpp
就好了,让我们来看看
SILLYDataSource.icpp
中写的是什么:
这是在另外的一个
SILLYFileDataSource.icpp
中的内容:
很清晰吧,哈哈,这应该就是大波哥所喜欢的类型
...
inline
,为了清晰的分别哪些是
inlie
的函数,哪些不是,则可以使用这样一种方法:用单独的文件存放
inline
函数。
在
cegui
的
silly
库的实现中,所有用到的
inlie
函数都被放在相应
.h
文件对应的
.icpp
文件中,比如:
SILLYDataSource.h
//
有这样的
inline
定义文件存在
SILLYDataSource.icpp
而在对应的
SILLYDataSource.cpp
中,这样处理:
#ifndef SILLY_OPT_INLINE
#define inline
#include "SILLYDataSource.icpp"
#undef inline
#endif
这个似乎有些多余,基本上在具体的实现文中,只要包含
SILLYDataSource.icpp
就好了,让我们来看看
SILLYDataSource.icpp
中写的是什么:
// Start of section namespace SILLY namespace SILLY { inline DataSource ::~DataSource () { } inline byte DataSource ::operator [](size_t offset ) const { assert (offset < getSize () && "ASSERT: Trying to access pixel outside of the data" ); return getDataPtr ()[offset ]; } } // End of section namespace SILLY |
SILLYFileDataSource.icpp
中的内容:
// Start of section namespace SILLY namespace SILLY { inline bool FileDataSource ::isValid () const { return d_error ; } inline const byte * FileDataSource ::getDataPtr () const { return d_bytes ; } inline size_t FileDataSource ::getSize () const { return d_size ; } } // End of section namespace SILLY |
...
相关文章推荐
- iOS安全–使用static inline方式编译函数,防止静态分析
- c++调用类内部使用成员变量和inline函数的区别
- inline函数使用容易导致出错的问题
- inline函数使用方法之二
- [置顶] 使用const定义常量,inline定义小型函数
- 使用DbgHelp获取函数调用堆栈之inline assembly(内联汇编)法
- 使用DbgHelp获取函数调用堆栈之inline assembly(内联汇编)法
- 使用单独的命令处理类来处理命令消息(适用于有很多命令处理函数的对象,以及共享命令处理函数)
- C语言inline函数使用
- iOS安全–使用static inline方式编译函数,防反编译
- 使用单独的命令处理类来处理命令消息(适用于有很多命令处理函数的对象,以及共享命令处理函数)
- 深入理解内联inline函数的优缺点,性能及使用指南
- C++之inline函数使用总结
- over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用
- 使用DbgHelp获取函数调用堆栈之inline assembly(内联汇编)法
- inline 函数的使用小结之一
- linux 下 利用反汇编 查看 inline函数的 使用
- Effective C++读书笔记--Item 2:使用const,enum和template inline函数代替宏
- 使用Intel编译器(4)IPO(2)函数内联(Inline Expansion of Functions)
- inline 函数的使用以及注意事项