Today, my friend and I struggled a lot with a stupid mistake, and I make you think about how the template parameters work in C ++. Consider the following code, where I am trying to partially specialize the class attr<MyClass<I>> , where I is an unsigned int , although MyClass expects an int parameter:
#include <iostream> template<int I> class MyClass { }; template<typename T> struct attr; template<unsigned int I> struct attr<MyClass<I>> { }; int main(int argc, char *argv[]) { attr<MyClass<1>> att; return 0; }
g++ comes out with an error message
main.cpp: In function 'int main(int, char**)': main.cpp:20:22: erreur : aggregate 'attr<MyClass<1> > att' has incomplete type and cannot be defined attr<MyClass<1>> att;
And clang compiles it (only a warning because att not used).
Therefore, I was wondering:
source share