We have two templated classes, Class1
has a nested class. Class2
needs to be constructed / converted from that nested class object.
template<typename T> struct Class1{
Class1() = default;
class Inner{};
};
template<typename T> struct Class2{
Class2() = default;
template<typename T2> Class2(const Class1<T2>&) {}
template<typename T2> Class2(const typename Class1<T2>::Inner&) {}
};
void foo(const Class2<int>&){}
...
Class1<int> c1;
Class1<int>::Inner i1;
foo( c1);
foo( i1); // <===================ERROR
Error text is:
error: invalid initialization of reference of type ???const Class2<int>&??? from expression of type ???Class1<int>::Inner???
Why do I get this error? Constructing from Class1
works. Constructing from Inner
if the classes are not templates also works.