473,378 Members | 1,482 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,378 software developers and data experts.

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::<=(mystery 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 5463
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::<=(mystery rightObj) //line 3 change to:
bool mystery::operator <=(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**********@phys-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**********@phys-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
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...
6
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
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...
7
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...
8
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...
3
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...
2
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...
8
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...
11
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...
0
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 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.