I have a nested template inside a parent template. I'd like instances of the nested template to be convertible to other classes instantiated from the same template (but with different parameters.) To do this, I create a constructor for the nested template that can take different template parameters:
template <class T>
struct Foo
{
template <class U>
struct Bar
{
Bar() { }
template <class X, class Y>
Bar(typename Foo<X>::template Bar<Y> b)
{
}
};
};
This should enable the following expression to compile:
Foo<int>::Bar<int> b = Foo<char>::Bar<char>();
However, it doesn't actually compile. It gives the compiler error:
error: conversion from ‘Foo<char>::Bar<char>’ to non-scalar type ‘Foo<int>::Bar<int>’ requested
Foo<int>::Bar<int> b = Foo<char>::Bar<char>();
So, I'm confused. Why doesn't this compile?