S
stella_pigeon
Can someone offer me a hint how to correctly program the problem
outlined below?
I have a template class defines as follows
class A {
int a1;
int a2;
operator == ...
}
class B {
int b1;
int b2;
operator == ...
}
template <class T> C : public T
{
int c;
operator ==... /* I am stuck right here */
}
typedef C<A> CA;
typedef C<B> CB;
main()
{
CA obj1, obc2; /* assume they are properly initialized */
if (obj1 == obj2) .....;
}
The implementation of the operator == in C must do the following:
(1) compare attribute c
(2) use a == operator of A or B depending on which of these is a base
class, in the example above it will be operator == of class A.
What is the correct implementation of operator == in class C?
I tried:
template <class T> BOOL C<T>:perator == (const C<T> &src) const
{
return (this->c == src.c && T:*this) == T::src);
}
but gcc rejects it with "error: expected unqualified-id before '('
token".
Can someone help?
outlined below?
I have a template class defines as follows
class A {
int a1;
int a2;
operator == ...
}
class B {
int b1;
int b2;
operator == ...
}
template <class T> C : public T
{
int c;
operator ==... /* I am stuck right here */
}
typedef C<A> CA;
typedef C<B> CB;
main()
{
CA obj1, obc2; /* assume they are properly initialized */
if (obj1 == obj2) .....;
}
The implementation of the operator == in C must do the following:
(1) compare attribute c
(2) use a == operator of A or B depending on which of these is a base
class, in the example above it will be operator == of class A.
What is the correct implementation of operator == in class C?
I tried:
template <class T> BOOL C<T>:perator == (const C<T> &src) const
{
return (this->c == src.c && T:*this) == T::src);
}
but gcc rejects it with "error: expected unqualified-id before '('
token".
Can someone help?