template and nested class problem

M

Miroslav Novak

Hi,
I can't compile the following code. Does anyone know where is the problem?
Thank you in advance,
Mirek.

code:
----------------

template<class T>
struct CA
{
struct CB
{
T* z;
};
};

template<class T>
void fun(typename CA<T>::CB x) {}; // line 56

void test()
{
CA<int>::CB x;
fun(x); // line 61
}

errors:
 
G

Gianni Mariani

Miroslav said:
Hi,
I can't compile the following code. Does anyone know where is the problem?
Thank you in advance,
Mirek.
....
errors:
------------

test.cpp(61) : error C2783: 'void fun(CA<T>::CB)' : could not deduce
template argument for 'T'
test.cpp(56) : see declaration of 'fun'

That's correct. It will not deduce T in this case.
 
F

Fraser Ross

Template parameter T of struct CA cannot be deduced from a nested template
class parameter. Presumably anyway. It is logical to me. Explicitly call
fun with <int>.

Fraser.
 

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
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top