What is the right syntax

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>::eek: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?
 
V

Victor Bazarov

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 == ...

bool operator == ...
} ;

class B {
int b1;
int b2;
operator == ...

bool operator == ...
} ;

template <class T> C : public T

template said:
{
int c;
operator ==... /* I am stuck right here */

bool operator == ...
} ;

typedef C<A> CA;
typedef C<B> CB;

main()

int 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>::eek:perator == (const C<T> &src) const

What's "BOOL"? Did you mean "bool"?
{
return (this->c == src.c && T::(*this) == T::src);
}

but gcc rejects it with "error: expected unqualified-id before '('
token".

Can someone help?

Should probably be

return c == src.c && this->T::eek:perator==(src);

Disclaimer: untested. I am as lazy to test as you were lazy to post
compilable code.

V
 
S

stella_pigeon

Victor said:
Should probably be

return c == src.c && this->T::eek:perator==(src);

Disclaimer: untested. I am as lazy to test as you were lazy to post
compilable code.

Hi Victor

It compiles. Thank you very much.

SP
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top