What means “obey ODR” in case of inline and constexpr function?

后端 未结 3 512
猫巷女王i
猫巷女王i 2021-01-13 19:22

I just read that constexpr and inline functions obey one-definition rule, but they definition must be identical. So I try it:

inline void foo() {
    return;         


        
3条回答
  •  遥遥无期
    2021-01-13 19:59

    If you have:

    file1.cpp:

    inline void foo() { std::cout << "Came to foo in file1.cpp" << std::endl; }
    

    and

    file2.cpp:

    inline void foo() { std::cout << "Came to foo in file2.cpp" << std::endl; }
    

    and you link those files together in an executable, you are violating the one-definition-rule since the two versions of the inline function are not same.

提交回复
热议问题