Template matching with inner classes

M

Mark Paskin

Hello, I'm having difficulty getting template matching to work with
inner classes. I've tried to look up the way to fix this in my
references, but I haven't found the fix yet. When I try to compile the
program below (g++ 3.3/4.0), I get

test.cpp: In function `int main()':
test.cpp:19: error: no match for 'operator<<' in 'std::cout << x'

Does anyone know what I'm doing wrong? Thanks!

Mark


#include <iostream>

template <typename T>
struct outer {
struct inner {
T z;
};
};

template <typename T>
std::eek:stream& operator<<(std::eek:stream& out,
typename outer<T>::inner& i) {
out << i;
return out;
}

int main(void) {
outer<int>::inner x;
std::cout << x;
return EXIT_SUCCESS;
}
 
V

Victor Bazarov

Mark said:
Hello, I'm having difficulty getting template matching to work with
inner classes. I've tried to look up the way to fix this in my
references, but I haven't found the fix yet. When I try to compile the
program below (g++ 3.3/4.0), I get

test.cpp: In function `int main()':
test.cpp:19: error: no match for 'operator<<' in 'std::cout << x'

Does anyone know what I'm doing wrong? Thanks!

Mark


#include <iostream>

template <typename T>
struct outer {
struct inner {
T z;
};
};

template <typename T>
std::eek:stream& operator<<(std::eek:stream& out,
typename outer<T>::inner& i) {
out << i;
return out;
}

int main(void) {
outer<int>::inner x;
std::cout << x;
return EXIT_SUCCESS;
}

Literally, less than a week ago, the same question was answered here.
Please, before posting again, take time to read the FAQ and the archives.

The program is invalid because T in operator<< cannot be deduced as 'int'.
The context outer<T>::inner is not one for which the Standard requires the
implementation to deduce T. You need to rethink your approach. Why do
you need to know T anyway?

V
 

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,202
Messages
2,571,057
Members
47,668
Latest member
SamiraShac

Latest Threads

Top