|
|
all kinds of problems with #ifndef
Im a student in a data structures class. I am currently trying to
build a class which uses overloaded binary operators. I am also
trying to understand the use of the #ifndef directive. The following
is my code:
#ifndef Time
#define Time
#include <algorithm>
class Time
{
public:
enum am_pm
{AM = 0, PM = 12};
//class constructors
Time()
{
hours = 12;
minutes = 0;
dayTime = am_pm::AM;
}
Time(unsigned int curHours, unsigned int curMinutes, am_pm
curDayTime)
{
setHours(curHours);
setMinutes(curMinutes);
dayTime = curDayTime;
}
//set methods
void setHours(unsigned int curHours)
{
if(curHours >= 0 && curHours <= 12)
hours = curHours;
}
void setMinutes(unsigned int curMinutes)
{
if(curMinutes >= 0 && curMinutes <=59)
minutes = curMinutes;
}
//get methods
unsigned int getHours()
{return hours;}
unsigned int getMinutes()
{return minutes;}
am_pm getDayTime()
{return dayTime;}
//member functions
//overloaded operator methods
bool operator==(Time &another)
{return Time::convertToMinutes() == another.convertToMinutes();}
bool operator > (Time &another)
{return Time::convertToMinutes() > another.convertToMinutes();}
bool operator < (Time &another)
{return Time::convertToMinutes() < another.convertToMinutes();}
private:
unsigned int hours;
unsigned int hours24;
unsigned int minutes;
am_pm dayTime;
//member methods
unsigned int convertToMinutes()
{return (hours + dayTime) * 60 + minutes;}
};
#endif //define Time
when I try to compile this I get the following error:
time.h(13) : error C2059: syntax error : '{'
Line 13 is the opening bracket of my class constructor.
Any help would be greatly appreciated. If I dont use the #ifndef
directive then the class compiles. I am mystified.
Thanks, Mark
|
|
0
|
|
|
|
Reply
|
Mark
|
7/24/2010 6:02:36 PM |
|
Mark Pfeif <mayeyeserveu@gmail.com> writes:
> Im a student in a data structures class. I am currently trying to
> build a class which uses overloaded binary operators.
<snip>
> #include <algorithm>
> class Time
Looks like you want to post in comp.lang.c++. This is a C group.
<snip>
--
Ben.
|
|
0
|
|
|
|
Reply
|
Ben
|
7/24/2010 6:24:18 PM
|
|
On Sat, 24 Jul 2010 11:02:36 -0700 (PDT), Mark Pfeif
<mayeyeserveu@gmail.com> wrote:
Don't do this:
>#ifndef Time
>#define Time
Don't define Time and then expect to be able to redefine it as a
class. Drop the #define and it will compile.
In future, ask c++ in the comp.lang.c++ group next door.
|
|
0
|
|
|
|
Reply
|
Geoff
|
7/24/2010 7:09:00 PM
|
|
Mark Pfeif <mayeyeserveu@gmail.com> writes:
> Im a student in a data structures class. I am currently trying to
> build a class which uses overloaded binary operators. I am also
> trying to understand the use of the #ifndef directive. The following
> is my code:
You wanted comp.lang.c++, not comp.lang.c, but your problem is one
that could occur in C as well.
> #ifndef Time
> #define Time
Here you define Time as a macro; it expands to nothing.
> #include <algorithm>
> class Time
What does the above line look like after macro substitution?
> {
> public:
>
> enum am_pm
> {AM = 0, PM = 12};
> //class constructors
> Time()
What does the above line look like after macro substitution?
[snip]
Macro names are conventionally all-caps; following that convention would
have avoided this problem.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21549)
|
7/24/2010 8:19:18 PM
|
|
|
3 Replies
159 Views
(page loaded in 1.482 seconds)
Similiar Articles: Edited and deleted contacts duplicate and reappear when syncing to ...I haven't had > trouble syncing to MobileMe, but Google syncing introduced all kinds of > problems, with duplicated and/or old contacts, or even bogus new entries ... Two Source Radiation Contour Issue - comp.soft-sys.matlab ...Besides providing advice and assistance in developing all kinds of university-level ... imagesc within a GUI. - comp.soft-sys ..... everyone , I'm encountering a problem ... Cepstrum Help - comp.dsp> > Computing the 'exact' log of the complex DFT coefficients > is an even greater mess, as you will be dealing with all > kinds of uniqueness issues caused by the complex ... f77 and dynamic arrays in common blocks - comp.lang.fortran ...But there are all kinds of caveats, complications, and limitations. The cost of ... STOPworworSPAM@bellsouth.net> writes: > 3) Some of us usually solve new problems ... Large Arrays - Memory Problems - comp.soft-sys.matlabDear All, I'm running into serious memory problems with Matlab 2010a and large arrays. ... vary quite a bit depending upon the kinds of problems ... Thus im not ... User Login Time - comp.sys.sun.adminThere are also all kinds of (security) issues with writing information back into the LDAP server. Take the last login time as an example: If you write this into the ... Cisco VPN 3030 client connectivity issues - comp.dcom.sys.cisco ...We are having all kinds of trouble whereas 3.0 and 3.6.3 have no issues. We are getting the reason 403 and the following log output: 53988 01/13/2004 17:13:26.470 SEV=5 ... ddd(gdb) problem - comp.unix.programmerddd(gdb) problem - comp.unix.programmer Debugging with gdb/ddd - Christopher ... program, and seeing the values of variables can help locate the same kind of problems ... classification of color images - comp.soft-sys.matlabAny decent medical image will have >> info in the header that will identify all kinds ... comp.soft-sys.matlab Lip-Feature Extraction - comp.soft-sys.matlab I have a problem ... Jumbled Screen before even POST - comp.sys.ibm.pc.hardware.video ...Hi all, I was given an old Tyan Tsunami ATX with a PII 450 ... what I choose, the screen afterwards is unreadable - it's all kinds of jumbled, unreadable lines. The problem ... All Kinds Of Problems – Free listening, concerts, stats ...Listen to All Kinds Of Problems: Never Say Never, Confusion & more, plus 2 pictures. Rap-metal band All Kinds of Problems was formed in northern New Jersey by co-MCs ... Teaching Different Types of Math Story ProblemsMany students struggle with word problems. Use the theory of Cognitively Guided Instruction (CGI) to help your students grasp these types of math problems. 7/15/2012 2:38:18 AM
|
|
|
|
|
|
|
|
|