473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the right syntax

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>::operator == (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?

Feb 16 '06 #1
2 1371
st***********@yahoo.ca wrote:
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<class T> class C : public T
{
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>::operator == (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::operator==(src);

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

V
--
Please remove capital As from my address when replying by mail
Feb 16 '06 #2

Victor Bazarov wrote:

Should probably be

return c == src.c && this->T::operator==(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

Feb 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
37
by: Bengt Richter | last post by:
ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
8
by: Hermawih | last post by:
Hello , I want your opinion about this . In order to say it clearly , I think I have to describe it in long sentences . I could consider myself as Intermediate/Advance Access Developer ;...
17
by: Anoob | last post by:
Can we consider () unary operator when calling a function, in exps eq. f(), ( 1 + 2). But when we call function f( 10 ) it is a binary operator. Even if we pass f( 10, 20) as we are using ,...
5
by: Cylix | last post by:
this.menus = { root: new Array };
8
by: clintonG | last post by:
Every single time neophytes or converts ask about naming and style conventions what are they told by the majority consensus? The answer is "do what you prefer but do so consistently" right? Yes,...
4
by: _Raven | last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt this script to my forms: http://www.captain.at/howto-ajax-form-post-get.php I have included my code at the bottom of this...
38
by: Zytan | last post by:
What is the difference between these two lines? Dim args As Object() = New Object() {strText} Dim args As Object() = {strText} args seems usuable from either, say, like so: ...
21
by: Ram Prasad | last post by:
I am trying to write a simple libspf2 plugin code for my postfix ( milter) I am getting this unhelpful error message when I try to compile gcc -g1 -Wall -I/usr/local/include/spf2 -I. -c mfunc.c...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.