|
-
April 9th, 2009, 02:02 PM
#1
overloading operation for inner class of class template
Hi!
I have a problem compiling the following code:
Code:
#include <iostream>
using namespace std;
template <typename T>
class Some_class
{
public:
class Inner;
};
template <typename T>
class Some_class<T>::Inner
{
public:
T member;
};
//----------------------------------------------------------------------------
template <typename T>
bool operator != ( typename const Some_class<T>::Inner &a,
typename const Some_class<T>::Inner &b
)
{
return ( a.member != b.member );
}
//----------------------------------------------------------------------------
int main( void )
{
Some_class<int>::Inner x, y;
x.member = 1;
y.member = 2;
cout << (x != y) << endl;
}
Particularly, operator != causes some errors (with g++):
tempcmp.cpp:37: error: declaration of `operator!=' as non-function
tempcmp.cpp:37: error: expected nested-name-specifier before "const"
tempcmp.cpp:37: error: expected identifier before "const"
tempcmp.cpp:37: error: expected `(' before "const"
tempcmp.cpp:38: error: expected nested-name-specifier before "const"
tempcmp.cpp:38: error: expected identifier before "const"
tempcmp.cpp:38: error: expected `(' before "const"
tempcmp.cpp:40: error: expected `;' before '{' token
tempcmp.cpp: In function `int main()':
tempcmp.cpp:57: error: no match for 'operator!=' in 'x != y'
This is a simplified version of a much complex code. That one was tested on MS Visual C++ 2005 Express. So it doesn't seem to be a compiler issue.
I could implement != as Inner's member. But in this case, how could I proceed expressions like:
<some int> != <some Inner>
?
Note that <some Inner> != <some int> does work if Inner's constructor Inner( int ) is implemented. But vice versa (<some int> != <some Inner>) does not!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|