#include <iostream>
using namespace std;
template<int k>
struct Base{
int a = k;
};
struct C1 : Base<1>{};
struct C2 : Base<2>{int b;};
typedef Base<1> C1T;
template<
typename BufferType,
typename VerticesType,
VerticesType BufferType::* VerticesField = nullptr
>
void t(){};
int main() {
// WHY this work??
t<C1T , int, &C1T::a>();
// And this not?
C1 c1;
t<C1 , int, &c1::a>();
// ok.
// t< Base<1>, int, &Base<1>::a >();
// also, ok
t<C2 , int, &C2::b>();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8aW50IGs+CnN0cnVjdCBCYXNlewogICBpbnQgYSA9IGs7Cn07CgpzdHJ1Y3QgQzEgOiBCYXNlPDE+e307CnN0cnVjdCBDMiA6IEJhc2U8Mj57aW50IGI7fTsKCnR5cGVkZWYgQmFzZTwxPiBDMVQ7CgoKICAgIHRlbXBsYXRlPAogICAgICAgICAgICB0eXBlbmFtZSBCdWZmZXJUeXBlLAoKICAgICAgICAgICAgdHlwZW5hbWUgVmVydGljZXNUeXBlLAogICAgICAgICAgICBWZXJ0aWNlc1R5cGUgQnVmZmVyVHlwZTo6KiBWZXJ0aWNlc0ZpZWxkID0gbnVsbHB0cgogICAgICAgICAgICA+CiAgICB2b2lkIHQoKXt9OwoKCmludCBtYWluKCkgewovLyBXSFkgdGhpcyB3b3JrPz8KCXQ8QzFUICwgaW50LCAmQzFUOjphPigpOwoKLy8gQW5kIHRoaXMgbm90PwpDMSBjMTsKdDxDMSAsIGludCwgJmMxOjphPigpOwoKLy8gb2suCi8vCXQ8IEJhc2U8MT4sIGludCwgJkJhc2U8MT46OmEgPigpOwoKLy8gYWxzbywgb2sKdDxDMiAsIGludCwgJkMyOjpiPigpOwoJcmV0dXJuIDA7Cn0=
prog.cpp: In function ‘int main()’:
prog.cpp:30:1: error: parse error in template argument list
t<C1 , int, &c1::a>();
^
prog.cpp:30:21: error: no matching function for call to ‘t()’
t<C1 , int, &c1::a>();
^
prog.cpp:30:21: note: candidate is:
prog.cpp:21:10: note: template<class BufferType, class VerticesType, VerticesType BufferType::* VerticesField> void t()
void t(){};
^
prog.cpp:21:10: note: template argument deduction/substitution failed:
prog.cpp:30:21: error: template argument 3 is invalid
t<C1 , int, &c1::a>();
^