2

複数の翻訳単位で、既定のテンプレート引数は異なるが同じ定義を持つ同じテンプレートの宣言を行うことはできますか? たとえば、b.cppとの翻訳単位c.cppが一緒にリンクされている場合、次のコードは ODR に違反しますか?

// a.hpp
template <bool> class x {...};

// b.cpp
template <bool = true> class x;
#include "a.hpp"
// uses of x<>

// c.cpp
template <bool = false> class x;
#include "a.hpp"
// uses of x<>
4

1 に答える 1