jeudi 20 avril 2017

Different C++ template typename definition means the same one?

template <typename T>
class A {
    int func(T a);

template <typename V>
int A<V>::func(V a) {
    return 0;

In Visual Studio 2017, when I wrote the above code, the editor shows that Function denfinition for 'func' not found, and it suggests me to create a new one, which uses typename T. However, I can still compile and run successfully.

It really confuses me. Is that a bug in Visual Studio? Does int A<V>::func(V a) just the same as int func(T a) in class A?

Is it a good practice to write the same typename in all declarations and definitions?


0 commentaires:

Enregistrer un commentaire