J
jdurancomas
Dear all,
I'm trying to declare the operator++ to a nested class. The nested
class is not template but the container it is.
The code used in teh sample program is included bellow:
#include <iostream>
template <class T>
class A
{
public:
class B;
};
template <class T>
bool operator == <T> (const A<T>::B &b1,
const class A<T>::B &b2);
template <class T>
class A<T>::B
{
public:
B(int a);
friend bool operator ==<> (const A<T>::B &b1, const A<T>::B &b2);
private:
int aa;
B b;
};
template <class T>
A<T>::B::B(int a):
aa(a)
{}
template <class T>
bool operator == <>(const A<T>::B& b1, const A<T>::B& b2)
{
return b1.aa == b2.aa;
}
class C {};
int main()
{
A<C> ac;
A<C>::B b1(4), b2(5);
bool res = (b1 == b2);
return 0;
}
I'm compiling with gcc version 4.1.2. The output of the compiler is
included bellow:
nested.cpp:13: error: expected initializer before '<' token
nested.cpp:23: error: expected unqualified-id before 'template'
nested.cpp:38: error: expected initializer before '<' token
nested.cpp: In instantiation of 'A<C>::B':
nested.cpp:51: instantiated from here
nested.cpp:27: error: 'A<T>::B::b' has incomplete type
nested.cpp:19: error: declaration of 'class A<C>::B'
nested.cpp: In function 'int main()':
nested.cpp:53: error: no match for 'operator==' in 'b1 == b2'
Any help will be appreciated.
Thanks and Best Regards,
Joaquim Duran
I'm trying to declare the operator++ to a nested class. The nested
class is not template but the container it is.
The code used in teh sample program is included bellow:
#include <iostream>
template <class T>
class A
{
public:
class B;
};
template <class T>
bool operator == <T> (const A<T>::B &b1,
const class A<T>::B &b2);
template <class T>
class A<T>::B
{
public:
B(int a);
friend bool operator ==<> (const A<T>::B &b1, const A<T>::B &b2);
private:
int aa;
B b;
};
template <class T>
A<T>::B::B(int a):
aa(a)
{}
template <class T>
bool operator == <>(const A<T>::B& b1, const A<T>::B& b2)
{
return b1.aa == b2.aa;
}
class C {};
int main()
{
A<C> ac;
A<C>::B b1(4), b2(5);
bool res = (b1 == b2);
return 0;
}
I'm compiling with gcc version 4.1.2. The output of the compiler is
included bellow:
nested.cpp:13: error: expected initializer before '<' token
nested.cpp:23: error: expected unqualified-id before 'template'
nested.cpp:38: error: expected initializer before '<' token
nested.cpp: In instantiation of 'A<C>::B':
nested.cpp:51: instantiated from here
nested.cpp:27: error: 'A<T>::B::b' has incomplete type
nested.cpp:19: error: declaration of 'class A<C>::B'
nested.cpp: In function 'int main()':
nested.cpp:53: error: no match for 'operator==' in 'b1 == b2'
Any help will be appreciated.
Thanks and Best Regards,
Joaquim Duran