Pure virtual functions may not have an inline definition. Why?

前端 未结 5 740
北海茫月
北海茫月 2020-11-28 05:45

Pure virtual functions are those member functions that are virtual and have the pure-specifier ( = 0; )

Clause 10.4 paragraph 2

5条回答
  •  旧巷少年郎
    2020-11-28 06:42

    Good guesses are welcome you say?

    I think the = 0 at the declaration comes from having the implementation in mind. Most likely this definition means, that you get a NULL entry in the RTTI's vtbl of the class information -- the location where at runtime addresses of the member functions of a class are stored.

    But actually, when put a definition of the function in your *.cpp file, you introduce a name into the object file for the linker: An address in the *.o file where to find a specific function.

    The basic linker then does need to know about C++ anymore. It can just link together, even though you declared it as = 0.

    I think I read that it is possible what you described, although I forgot the behaviour :-)...

提交回复
热议问题