How to deduce template argument implicitly?

N

Nephi Immortal

I already explicitly defined X< 1 > x since argument explicitly exists. I do not want to tell the Compiler to deduce the template argument in Test() function, but it should be done implicitly.

error C2783: 'void Test(const X<T>::Y &)' : could not deduce template argument for 'T'

template< int T >
class X
{
private:
class Y
{
public:
Y() {}
~Y() {}

void Do() const {}
};

template< int T >
friend void Test( typename const X< T >::Y& ref );

public:
X() {}
~X() {}

Y Go() { return Y(); }
};

template< int T >
void Test( typename const X< T >::Y& ref )
{
ref.Do();
}


int main()
{
X< 1 > x;

Test< 1 >( x.Go() ); // OK
// Test( x.Go() ); // error C2783: 'void Test(const X<T>::Y &)' : could not deduce template argument for 'T'

return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top