Can someone please help me to understand why the following code does not compile:
template< typename T >
class A
{};
template< typename U >
class wrapper
{
public:
// cast operator
operator wrapper< A<void> > ()
{
return wrapper< A<void> >{};
}
};
template< typename T >
void foo( wrapper< A<T> > )
{}
int main()
{
foo( wrapper<void>{} );
}
error message:
t.cpp:24:7: error: no matching function for call to 'foo'
foo( wrapper<void>{} );
^~~
t.cpp:18:10: note: candidate template ignored: could not match 'A<type-parameter-0-0>' against 'void'
void foo( wrapper< A<T> > )
^
1 error generated.
and how to fix it?
I expected that wrapper<void> is casted to wrapper< A<void > using the cast operator of class wrapper.