CSDN博客

img Betta

C++ Coding Tips - Chapter1

发表于2002/4/18 9:28:00  2200人阅读


C++ Coding Tips

Betta Jin
<betajin@hotmail.com>

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.



0 0

相关博文

我的热门文章

img
取 消
img