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

Help with my code? Classes

I am trying to program a couple classes. One is called PositiveInteger and
is supposed to just store a positive integer. The second class is called
Circle, and is meant to describe a circle. Circle is meant to use
PositiveInteger when describing the circle's radius. Sorry if haven't
described it properly.

Could someone take a look at my code and tell me where I am going wrong, and
why it keeps giving me this error

error C2533: 'Circle::Circle' : constructors not allowed a return type

Thanks.
I'll post the 4 code files as replies to this message.
Jul 19 '05 #1
15 7235
// file: PositiveInteger.h

#ifndef POSITIVEINTEGER_H
#define POSITIVEINTEGER_H

//-------------------------------------------------------------------

#include <iostream.h>

//-------------------------------------------------------------------

class PositiveInteger
{
public:
/* constructors */
PositiveInteger(); // default
PositiveInteger(const PositiveInteger &posInt); // copy
~PositiveInteger() {}; // destructor
void Clear(); // clear value to 0

/* set method */
bool SetValue(int);

/* get method */
int GetValue() const {return m_value;}

/* overload operators */
PositiveInteger &operator = (const PositiveInteger &posInt);
bool operator < (const PositiveInteger &posInt);
bool operator > (const PositiveInteger &posInt);
bool operator == (const PositiveInteger &posInt);

/* input/output methods */
friend ostream& operator << (ostream &ostr, const PositiveInteger &posInt);
friend istream& operator >> (istream &istr, PositiveInteger &posInt);

private:
int m_value;
};

#endif;
Jul 19 '05 #2
// file: PositiveInteger.cpp

#include "PositiveInteger.h"

//-------------------------------------------------------------------

PositiveInteger::PositiveInteger()
{
Clear();
}

//-------------------------------------------------------------------

PositiveInteger::PositiveInteger(const PositiveInteger &posInt)
{
SetValue(posInt.m_value);
}

//-------------------------------------------------------------------
/*
PositiveInteger::~PositiveInteger()
{
// do nothing
}
*/
//-------------------------------------------------------------------

void PositiveInteger::Clear()
{
SetValue(0);
}

//-------------------------------------------------------------------

bool PositiveInteger::SetValue(int value)
{
if (value < 0)
{
m_value = 0; // if negative, set to 0
return false;
}
else
{
m_value = value;
return true;
}
}

//-------------------------------------------------------------------

PositiveInteger &PositiveInteger::operator = (const PositiveInteger &posInt)
{
if (this != &posInt)
SetValue(posInt.m_value);

return *this;
}

//-------------------------------------------------------------------

bool PositiveInteger::operator < (const PositiveInteger &posInt)
{
if (m_value < posInt.m_value)
return true;
else
return false;
}

//-------------------------------------------------------------------

bool PositiveInteger::operator > (const PositiveInteger &posInt)
{
if (m_value > posInt.m_value)
return true;
else
return false;
}

//-------------------------------------------------------------------

bool PositiveInteger::operator == (const PositiveInteger &posInt)
{
if (m_value == posInt.m_value)
return true;
else
return false;
}

//-------------------------------------------------------------------

ostream& operator << (ostream &ostr, const PositiveInteger &posInt)
{
ostr << "Value: " << posInt.m_value;
return ostr;
}

//-------------------------------------------------------------------

istream& operator << (istream &istr, PositiveInteger &posInt)
{
int value;

do
{
cout << "Enter a positive integer: ";
istr >> value;
}while(!posInt.SetValue(value));
return istr;

}

//-------------------------------------------------------------------
Jul 19 '05 #3
// file: Circle.h

#ifndef CIRCLE_H
#define CIRCLE_H

//-------------------------------------------------------------------

#include <iostream.h>
#include "PositiveInteger.h"

//-------------------------------------------------------------------

class Circle
{
public:
/* constructors */
Circle(); // default
Circle(int radius, int x, int y);
Circle(const Circle &circle); //copy
~Circle() {}; // destructor
void Clear(); // clear circle to 0.....not sure how it works?

/* set methods */
bool SetRadius(int radius);
bool SetX(int);
bool SetY(int);

/* get methods */
int GetRadius() {return m_radius.GetValue();}
int GetX() const {return m_x;}
int GetY() const {return m_y;}
double GetPerimeter();
double GetArea();//what to do for these?

/* input/output methods */
//friend ostream& operator << (ostream &ostr, const Circle &circle);
//friend istream& operator >> (istream &istr, Circle &circle);

private:
PositiveInteger m_radius;
int m_x;
int m_y;
}

#endif
Jul 19 '05 #4
// file: Circle.cpp

#include "Circle.h"

//-------------------------------------------------------------------

Circle::Circle()
{
Clear();
}

//-------------------------------------------------------------------

Circle::Circle(int radius, int x, int y)
{
SetRadius(radius);
SetX(x);
SetY(y);
}

//-------------------------------------------------------------------

Circle::Circle(const Circle &circle)
{
SetRadius(circle.m_radius.GetValue());
SetX(circle.m_x);
SetY(circle.m_y);
}

//-------------------------------------------------------------------

void Circle::Clear()
{
m_radius.SetValue(0);
SetRadius(0);
SetX(0);
SetY(0);
}

//-------------------------------------------------------------------

bool Circle::SetRadius(int radius)
{
if (m_radius.SetValue(radius))
{
m_radius.SetValue(radius);
return true;
}
else
return false;
}

//-------------------------------------------------------------------

bool Circle::SetX(int x)
{
m_x = x;
return true;
}

//-------------------------------------------------------------------

bool Circle::SetY(int y)
{
m_y = y;
return true;
}

//-------------------------------------------------------------------

Jul 19 '05 #5


J Peterman wrote:

I am trying to program a couple classes. One is called PositiveInteger and
is supposed to just store a positive integer. The second class is called
Circle, and is meant to describe a circle. Circle is meant to use
PositiveInteger when describing the circle's radius. Sorry if haven't
described it properly.

Could someone take a look at my code and tell me where I am going wrong, and
why it keeps giving me this error

error C2533: 'Circle::Circle' : constructors not allowed a return type


It would help if you indicate *which* file gave that error.

But loook in Circle.h
You lost the ';' to end the class declaration

class Circle
{
....
} ;

^
|
missing

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #6
On Wed, 17 Sep 2003 16:39:45 +0800, J Peterman <mr********@hotmail.com> wrote:
[snip]
class Circle
{ [snip public section]
private:
PositiveInteger m_radius;
int m_x;
int m_y;
}

^
A character is missing here. The PositiveInteger.h has that character,
so it shouldn't be hard to work out :)

--
Sam Holden

Jul 19 '05 #7
Thanks a lot!
I knew it would be something stupid like that. I just couldn't see it...

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...


J Peterman wrote:

I am trying to program a couple classes. One is called PositiveInteger and is supposed to just store a positive integer. The second class is called
Circle, and is meant to describe a circle. Circle is meant to use
PositiveInteger when describing the circle's radius. Sorry if haven't
described it properly.

Could someone take a look at my code and tell me where I am going wrong, and why it keeps giving me this error

error C2533: 'Circle::Circle' : constructors not allowed a return type


It would help if you indicate *which* file gave that error.

But loook in Circle.h
You lost the ';' to end the class declaration

class Circle
{
....
} ;

^
|
missing

--
Karl Heinz Buchegger
kb******@gascad.at

Jul 19 '05 #8
Hi all,

wasn't the destructor implemented inline inside the class?

Should produce a compile error, or not?

Reagrds,
Patrick
//-------------------------------------------------------------------
/*
PositiveInteger::~PositiveInteger()
{
// do nothing
}
*/
//-------------------------------------------------------------------

Jul 19 '05 #9
Sorry, I am not exactly sure what I am doing...still new to this. If I'm not
mistaken, the destructor is commented cos I wasn't sure if I needed it or
not..

"Patrick Kowalzick" <Pa***************@cern.ch> wrote in message
news:bk**********@sunnews.cern.ch...
Hi all,

wasn't the destructor implemented inline inside the class?

Should produce a compile error, or not?

Reagrds,
Patrick
//-------------------------------------------------------------------
/*
PositiveInteger::~PositiveInteger()
{
// do nothing
}
*/
//-------------------------------------------------------------------


Jul 19 '05 #10

"J Peterman" <mr********@hotmail.com> wrote in message
news:bk**********@nnrp.waia.asn.au...
Thanks a lot!
I knew it would be something stupid like that. I just couldn't see it...


That is a tough error to find as the compiler message will always be
misleading to you. But, after some experience, you'll be able to spot this
error even based on funny error messages.
Jul 19 '05 #11

jeffc <no****@nowhere.com> wrote in message
news:3f********@news1.prserv.net...

"J Peterman" <mr********@hotmail.com> wrote in message
news:bk**********@nnrp.waia.asn.au...
Thanks a lot!
I knew it would be something stupid like that. I just couldn't see it...
That is a tough error to find as the compiler message will always be
misleading to you. But, after some experience, you'll be able to spot

this error even based on funny error messages.


Even better, develop coding habits that prevent this from
happening at all. E.g. when you define a class, write the
entire 'skeleton' first, e.g.

class MyClass
{
};

Then go back and fill it in.

Much easier to visually verify that all the syntax is
correct than when your class gets full of declarations, etc.

-Mike

Jul 19 '05 #12
Even better, develop coding habits that prevent this from
happening at all. E.g. when you define a class, write the
entire 'skeleton' first, e.g.

class MyClass
{
};

Then go back and fill it in.

Much easier to visually verify that all the syntax is
correct than when your class gets full of declarations, etc.

-Mike


Yeah, I started doing that! Thanks!
Jul 19 '05 #13
> > > //-------------------------------------------------------------------
/*
PositiveInteger::~PositiveInteger()
{
// do nothing
}
*/
//-------------------------------------------------------------------


oh, sorry, overseen the comment. I miss syntax-highligthing for my
newsreader ;-).

Patrick
Jul 19 '05 #14
J Peterman wrote:
Even better, develop coding habits that prevent this from
happening at all. E.g. when you define a class, write the
entire 'skeleton' first, e.g.

class MyClass
{
};

Then go back and fill it in.

Much easier to visually verify that all the syntax is
correct than when your class gets full of declarations, etc.

-Mike

Yeah, I started doing that! Thanks!


Also, always look *very closely* at the 2 or 3 lines ABOVE the line an
error is reported on. Sometimes those lines are not in the same file,
though.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #15

"Kevin Goodsell" <us*********************@neverbox.com> wrote in message
news:cf****************@newsread4.news.pas.earthli nk.net...

Also, always look *very closely* at the 2 or 3 lines ABOVE the line an
error is reported on. Sometimes those lines are not in the same file,
though.


Key point - that's why that one's so tricky.
Jul 19 '05 #16

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

Similar topics

6
by: Jax | last post by:
I have Visual Studio 2002 Standard Edition. It has been working fine up to a point and now i'm at that point. Due to the limitations of the edition i am not using any of my own .dll's and instead...
9
by: Jordan Tiona | last post by:
I can't get this code to work right. It seems to be skipping some of the cin functions. Can someone help me with this? ClassTrack.cpp: #include <iostream> #include "ClassTrack.h" using...
4
by: Tarun Mistry | last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies to both (apologies if it breaks some group rules). I am making a web app in asp.net using c#. This is the first fully OO...
1
by: D Witherspoon | last post by:
Coming up with a scenario here. For example there is the standard .NET MailMessage class. I am creating a project (let's call it CommonBase) that has the following 2 classes ...
6
by: Bill foust | last post by:
I'm running into a situation there I think an operator overload would solve the issue, but I'm unable to make it work for some reason. If anyone can help here I would appreciate it. I have a...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
0
by: pedz | last post by:
I am trying to write a set of classes, probably template classes, to allow "pretty" and safe access to low level machine words. The syntax I would like to end up with is something like: foo =...
5
by: QbProg | last post by:
Hello, I did some experiments with VC++ 2005, and some ILDasm. Please tell me if I have understood the concepts of C++ programming under .NET, since I'm a bit confused! -- There are 4 types of...
9
by: Chrissy | last post by:
I took a C# class as an elective and received an incomplete in it and am desparate for help. I have two assignments left (arrays and inheritance) and would gladly pay anyone that can assist me with...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.