If I have a header foo.h which I include all over my project, it seems to work fine when all it contains is:
template<typename T>
void foo(const T param) {
cout << param << endl;
}
But I get one definition rule (ODR) errors when I add a specalization to foo.h:
template<>
void foo(const bool param) {
cout << param << endl;
}
Obviously I can solve this by inline
'ing the specialization. My question is, why do I need to? If the template doesn't violate ODR, why does a specialization?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…