对inline函数使用单独的定义文件

  为了提高效率,类中的一些帮助器函数经常使用 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

 

很清晰吧,哈哈,这应该就是大波哥所喜欢的类型 ...

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值