How can a C++ header file include implementation?

前端 未结 7 1732
有刺的猬
有刺的猬 2020-11-28 02:51

Ok, not a C/C++ expert by any means, but I thought the point of a header file was to declare the functions, then the C/CPP file was to define the implementation.

How

7条回答
  •  爱一瞬间的悲伤
    2020-11-28 03:35

    It is implicitly declared inline by virtue of being a member function defined within the class declaration. This does not mean the compiler has to inline it, but it means you won't break the one definition rule. It is completely unrelated to const*. It is also unrelated to the length and complexity of the function.

    If it were a non-member function, then you would have to explicitly declare it as inline:

    inline void foo() { std::cout << "foo!\n"; }
    

    * See here for more on const at the end of a member function.

提交回复
热议问题