473,804 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help on some c++ hw


data structures teacher gave me like 50 questions, I have a few I'm not
sure about. My last c++ class was like 8 months ago and I can't
remember a lot of things. If anyone could help me on any of the
following questions, it'd be great.

Find the errors in the follwing code:

-First one

class mystery //line 1

{

...

bool operator <= (mystery); //line 2

...

};

bool mystery::<=(mys tery rightObj) //line 3

{

...

}

-Second one

class mystery //line 1

{

...

friend operator+ (mystery); //line 2

//Overload the binary operator +

...

};

And the last ones are:

How many parameters are required to overload the preincrement operator
for a class as a friend function?

How many parameters are required to overload the postincrement operator
for a class as a member function?

Any help would be appreciated.
--
Posted via http://dbforums.com
Jul 19 '05 #1
9 5487
It has been a while since I haven't used c++ operator overloading, however:
-First one

class mystery //line 1

{

...

bool operator <= (mystery); //line 2

...

};

bool mystery::<=(mys tery rightObj) //line 3 change to:
bool mystery::operat or <=(mystery rightObj) //line 3

-Second one

class mystery //line 1

{

...

friend operator+ (mystery); //line 2 change to:
friend operator+ (mystery, mystery); //line 2
//Overload the binary operator +

...

};

And the last ones are:
How many parameters are required to overload the preincrement operator
for a class as a friend function? Two.

How many parameters are required to overload the postincrement operator
for a class as a member function?

Two.
Would be glad if someone corrects me in case of mistakes.
--
Elias
Jul 19 '05 #2
lallous wrote:
It has been a while since I haven't used c++ operator overloading, however:
....
-Second one

class mystery //line 1

{

...

friend operator+ (mystery); //line 2
change to:
friend operator+ (mystery, mystery); //line 2


I don't think so.
//Overload the binary operator +

...

};

And the last ones are:

How many parameters are required to overload the preincrement operator
for a class as a friend function?


Two.


I don't think so.

How many parameters are required to overload the postincrement operator
for a class as a member function?


Two.


To the OP. You can easily find out if you use a compiler to check it out.

If you demonstrate some actual work in attempting to solve your problem,
you will get far greater levels of support from this NG - even if it's
homework.

If a job candidate could not answer these questions and this is all they
showed, the interview would be awfully short.

Jul 19 '05 #3
WW
Gianni Mariani wrote:
lallous wrote:
friend operator+ (mystery); //line 2


change to:
friend operator+ (mystery, mystery); //line 2


I don't think so.


Proof?
How many parameters are required to overload the preincrement
operator
for a class as a friend function?


Two.


I don't think so.


Proof?
--
WW aka Attila
Jul 19 '05 #4
WW wrote:
....

Proof?

....
Proof?

Please don't feed the TROLLS.
Jul 19 '05 #5
WW
Gianni Mariani wrote:
WW wrote:
...

Proof?

...

Proof?


Please don't feed the TROLLS.


OK, sorry. I did not realize you were trolling:

"To utter a posting on Usenet designed to attract predictable responses or
flames; or, the post itself."

But as I read it again (stating something is wrong without telling what it
is therefore not helping really but attracting attention for possible follow
up posts with contents wondering about the necessity of yours) you really
have been trolling.

--
WW aka Attila
Jul 19 '05 #6
In article <bk**********@p hys-news1.kolumbus. fi>, wo***@freemail. hu
says...
Gianni Mariani wrote:
lallous wrote:
friend operator+ (mystery); //line 2

change to:
friend operator+ (mystery, mystery); //line 2


I don't think so.


Proof?


He said he didn't think so -- given an inability to read minds, about
the closest thing there is to proof is the fact that he's said so, and
he doesn't seem to have any reason to lie about it.

Now, as to why he might think that: because it's a BAD idea. It'll
normally _work_ as it is, but will often be substantially less efficient
than it could be. As a general rule, you're better off with your
parameters as constant references than making them objects. The latter
requires that the objects be copied, which should normally be avoided
unless copying these objects is known to be cheap. No information to
that affect has been provided, and the name "mystery" seems intended to
indicate that we know relatively little about the class in question.
How many parameters are required to overload the preincrement
operator for a class as a friend function?

Two.


I don't think so.


Proof?


Much as above.

However, in this case there's no question that his thinking is
absolutely correct. If the non-member overload of operator++ takes two
parameters, it'll be a post-increment rather than a pre-increment (see
$13.5.7 if you want proof of that).

Unlike many operators, however, ++ and -- should normally be overloaded
as member functions. The usual reason for making operators global is to
support implicit conversions on the left operand. Since ++ and --
normally modify the object to which they're applied, supporting implicit
conversions is usually undesirable.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #7
WW
Jerry Coffin wrote:
friend operator+ (mystery, mystery); //line 2

I don't think so.
Proof? [SNIP] Now, as to why he might think that: because it's a BAD idea. It'll
normally _work_ as it is, but will often be substantially less
efficient than it could be. As a general rule, you're better off
with your parameters as constant references than making them objects.
The latter requires that the objects be copied, which should normally
be avoided unless copying these objects is known to be cheap. No
information to that affect has been provided, and the name "mystery"
seems intended to indicate that we know relatively little about the
class in question.
This is exactly the thing I was missing. The reply was arrogant. The
person why has tried to help was (I am sure) not deliberately misleading.
He did not deserve that kind of tone. And telling what is wrong is why we
are all here. Not to show up with arrogant, empty statements.
> How many parameters are required to overload the preincrement
> operator for a class as a friend function?

Two.

I don't think so.


Proof?

[SNIP] However, in this case there's no question that his thinking is
absolutely correct.
I know. He could have explained it. If he does not want to help he can
save all of us the time. If he wants, he can do it as you did.
If the non-member overload of operator++ takes
two parameters, it'll be a post-increment rather than a pre-increment
(see $13.5.7 if you want proof of that).
Eggzakt lee. I would not have required a reference to the standard in the
post I claim to be arrogant, but a simple description.
Unlike many operators, however, ++ and -- should normally be
overloaded as member functions. The usual reason for making
operators global is to support implicit conversions on the left
operand. Since ++ and -- normally modify the object to which they're
applied, supporting implicit conversions is usually undesirable.


Certainly. That's why I have absolutely forgot to write the non-member
version into my answer. Which is of course my mistake - but I actually do
not like to put things outside if I can put them inside - so I have never
ever used the non-member form.

--
WW aka Attila
Jul 19 '05 #8
Jerry Coffin wrote:
In article <bk**********@p hys-news1.kolumbus. fi>, wo***@freemail. hu
says...
Gianni Mariani wrote:
lallous wrote:

> friend operator+ (mystery); //line 2

change to:
friend operator+ (mystery, mystery); //line 2

I don't think so.


Proof?

He said he didn't think so -- given an inability to read minds, about
the closest thing there is to proof is the fact that he's said so, and
he doesn't seem to have any reason to lie about it.

Now, as to why he might think that: because it's a BAD idea. It'll
normally _work_ as it is, but will often be substantially less efficient
than it could be. As a general rule, you're better off with your
parameters as constant references than making them objects. The latter
requires that the objects be copied, which should normally be avoided
unless copying these objects is known to be cheap. No information to
that affect has been provided, and the name "mystery" seems intended to
indicate that we know relatively little about the class in question.


They are all really good points. But my issue is this:

error: ISO C++ forbids declaration of `operator+' with no type

It took 30 seconds to get this out of a compiler. It takes 5 minutes to
post and possibly hours to get a response.

The reason why I did not answer the questions were because this has to
do with school work and the original poster did not demonstrate even
tring to compile the code to see what errors there were. Had I seen
even a small attempt by the OP at solving the problems I would have
answered the questions.

As to why I responded at all. Apart from not helping people who don't
help themselves, I don't believe you should let anyone be misinformed,
even slightly. So, I felt obliged to at least hint that there was an
issue with the answers. If anyone read any *TONE* in the response,
you're horribly mistaken.

As for WW, I think he has an axe to grind and is simply trolling. He's
obviously smart enough to comprehend why I wrote what I did and smart
enough to have figured out the errors for himself. It's better not to
respond. Hence my plea for everyone to "Please don't feed the ...".
He'll get over it soon enough.

Jul 19 '05 #9
WW
Gianni Mariani wrote:
They are all really good points. But my issue is this:

error: ISO C++ forbids declaration of `operator+' with no type

It took 30 seconds to get this out of a compiler. It takes 5 minutes
to post and possibly hours to get a response.
Apparently you have a compiler. The OP might not have one.

[SNIP accusation of the OP to be lazy]
As to why I responded at all. Apart from not helping people who don't
help themselves, I don't believe you should let anyone be misinformed,
even slightly.
Better to leave them uninformed and bash them without knowing what they
could or could nto do.
So, I felt obliged to at least hint that there was an
issue with the answers. If anyone read any *TONE* in the response,
you're horribly mistaken.
Arrogant. That is the tone.
As for WW, I think he has an axe to grind and is simply trolling.
You are arrogant again. Stop calling me troll. I do not appreciate it.
You have posted an absolutely empty (therefore confusing to the OP),
unhelpful, arrogant post. I haver asked for proof. As you can see: it can
be done.
He's obviously smart enough to comprehend why I wrote what I did and
smart enough to have figured out the errors for himself.
And I am smart enough to figure out your silly ways of posting a reply to
someone else (having basically nothing to do whatsoever with the post you
reply to) but in reality replying to me.
It's better not to respond.
That's why you do it, behind my back, trying to show it up as a reply to
someone else. This all game calling me troll and trying to paint me black
behind my back is childish, just liek your arrogant post I have replied to.
Grow up!
Hence my plea for everyone to "Please don't feed the
...". He'll get over it soon enough.


Please stop being a mind reader. you are very very bad at it. As for you
trying to figure out my intentions - it is not working.

Trolling is what you do. You post flaim baits, and this was nto the first
one. Stop doing it. And get off my back, because I do not appreciate it.
Get a girlfriend and sc**w her. I am not into it.

--
WW aka Attila
Jul 19 '05 #10

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

Similar topics

0
2474
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its last year we got traffic of between 2000 - 2500 unique visitors per day. We are now about to re-launch the site from Sweden and we need to purchase a script to run it. Having looked at what is available on the net I have realised that we need a...
6
2189
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
2445
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to parse them to have a tree representation such as :
7
4393
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a few features that you'd expect in any editor, except nearly none of them seem to have: 1 - Search and repalce with Regular Expressions. 2 - Search and Replace in an Xpath context. 3 - User specified tag-generation for either on a...
8
2849
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl list class must Ioverride in order for this to work?
3
2642
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If you need more detail I can be glad to prove all my points. Our goal is to make logical systems. We don't want php,perl, or c++ making all the procedure calls and having the host language to be checking for errors and handleing all the...
2
1954
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a valid IP Address", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand) txtIPAddress.Focus() Return End If
8
2754
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only the sequence nos and it should be such that i can access it through the structure .plz help me .
11
4502
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
0
3969
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.