E
Eddie Parker
Hi!
I'm having an interesting problem that I can't seem to get to work, and
I'm curious if someone could either a) tell me how to make it work, or
b) tell me why it *can't* work.
Anyhow, here's a small test case that should compile on most compilers:
#include <iostream>
using namespace std;
template<typename T>
class TemplatedOuter
{
public:
class NestedInner
{
public:
int a;
NestedInner() : a(0) {};
};
TemplatedOuter() : m_NestedInner() {};
NestedInner m_NestedInner;
};
/**
* This does not.
*/
template<typename T>
ostream operator<<(ostream &os, typename TemplatedOuter<T>::NestedInner
const &nestedInner)
{
}
/**
* This works...
*/
template<typename T>
ostream operator<<(ostream &os, TemplatedOuter<T> const
&templatedOuter)
{
}
int main(void)
{
TemplatedOuter<int> a;
// This works.
cout << a;
// This does not.
cout << a.m_NestedInner;
}
/**
Output:
main.cpp: In function `int main()':
main.cpp:39: error: no match for 'operator<<' in 'std::cout <<
a.TemplatedOuter<int>::m_NestedInner'
*/
As you can see, I'm trying to basically have a nested public class, and
print out the contents of it... But it can't seem to find it... Any
suggestions on what I'm doing wrong, would be appreciated!
Thanks!
I'm having an interesting problem that I can't seem to get to work, and
I'm curious if someone could either a) tell me how to make it work, or
b) tell me why it *can't* work.
Anyhow, here's a small test case that should compile on most compilers:
#include <iostream>
using namespace std;
template<typename T>
class TemplatedOuter
{
public:
class NestedInner
{
public:
int a;
NestedInner() : a(0) {};
};
TemplatedOuter() : m_NestedInner() {};
NestedInner m_NestedInner;
};
/**
* This does not.
*/
template<typename T>
ostream operator<<(ostream &os, typename TemplatedOuter<T>::NestedInner
const &nestedInner)
{
}
/**
* This works...
*/
template<typename T>
ostream operator<<(ostream &os, TemplatedOuter<T> const
&templatedOuter)
{
}
int main(void)
{
TemplatedOuter<int> a;
// This works.
cout << a;
// This does not.
cout << a.m_NestedInner;
}
/**
Output:
main.cpp: In function `int main()':
main.cpp:39: error: no match for 'operator<<' in 'std::cout <<
a.TemplatedOuter<int>::m_NestedInner'
*/
As you can see, I'm trying to basically have a nested public class, and
print out the contents of it... But it can't seem to find it... Any
suggestions on what I'm doing wrong, would be appreciated!
Thanks!