|
-
Nov 6th, 2001, 09:00 PM
#1
Thread Starter
Lively Member
basic c++ question
Hi Everyone,
I'm trying to call a class called time....
class Time //define the time class which is managed by the track.
{
//friend Time operator++(Time&);
private:
int mins;
int secs;
public:
//Time(int m= 0, int s= 0)
//{ setTime(m,s); }
//bool setTime(int, int);
void increase(void);
int get_seconds()
{return secs; }
int get_mins()
{return mins;}
};
Iam declaring the time class in my manager class called track like this...
class track //define track class
{
Time timer;
etc etc
};
However, I keep getting this error....
error C2501: 'Time' : missing storage-class or type specifiers
What is going wrong???
any help would greatly be appreciated!
Smithy.
-
Nov 6th, 2001, 10:04 PM
#2
transcendental analytic
on what line do you get the error?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 6th, 2001, 10:07 PM
#3
The Time class must be defined above any code that uses it. So:
Code:
class Time { ... };
class track { ... };
...will be just fine.
Z.
-
Nov 6th, 2001, 10:08 PM
#4
Thread Starter
Lively Member
-
Nov 6th, 2001, 10:12 PM
#5
Hyperactive Member
How come you have no class constructor and destructor?
Is this allowed? Any C++ experts can explain?
-
Nov 6th, 2001, 10:12 PM
#6
Thread Starter
Lively Member
Hi Zaei,
can you explain what you mean in more detail?
Thanks.
-
Nov 6th, 2001, 10:14 PM
#7
transcendental analytic
oddly it just compiles for me.
you can but don't have to do as Zaei mentioned if you declare them:
class Time;
class track;
on top of your file
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 6th, 2001, 10:22 PM
#8
Thread Starter
Lively Member
here's the source
Hi guys,
thanks for the hlep so far, i can't understand why it's not working, I have included my c++ code with this post, i have a lot of other stupid little errors in this program as well, if you all could have a look at why the timer object isn't workin and maybe anything else which you can easily fix in it it would be very greatly apprecited!
Thanks.
Best Regards,
Ben Smith.
-
Nov 6th, 2001, 10:32 PM
#9
transcendental analytic
eek! That's a load of errors, try to compile once in a while as you code further...
Anyways, declare
class Time;
at the top and that problem should be over
if you don't understand the errors, look them up in msdn.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 6th, 2001, 10:39 PM
#10
Thread Starter
Lively Member
Hi kedaman,
Thanks for that, do i clear it up the top of the track class ie.
class track
{
class Time;
or at the top of the header file below the include statements.
Oh and also, I am stuck on quite a few of the errors, do you know how to fix any more of them? whatever help i can get will be greatly appreciated!
Best Regards,
Ben Smith.
-
Nov 7th, 2001, 06:01 AM
#11
I corrected some of the errors, now there are only 87 left.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 06:23 AM
#12
Thread Starter
Lively Member
thanks!
Thanks Bee!
I've kinda been working non stop though and i'm down to 12!
It's reall fusteraring getting the last of them! i'll put the new source on here now....
-
Nov 7th, 2001, 06:26 AM
#13
at the moment I'm working on a list of tips for you...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 06:30 AM
#14
Thread Starter
Lively Member
new source
here's the new source, so close to being complete!
-
Nov 7th, 2001, 06:36 AM
#15
This is for the old source, I haven't seen the new yet.
I stopped correcting errors because I didn't know what you wanted to do. Here are some tips on general programming:
I) General programming
1) strcpy is only used for strings, not for any other data types. To copy ints or doubles, use =
2) Only use variables you really declared. Check the variable scope. Don't use names that are already used by the standard library (exit() is a function).
3) Be aware of double includes. Put that into every header you write:
Code:
#ifndef _SOME_NAME_THAT_IS_USED_ONLY_HERE
#define _SOME_NAME_THAT_IS_USED_ONLY_HERE
// code goes here
#endif
4) array names can't be assigned to. If the array is used as string, this is the time to use strcpy.
II) CLASSES
1) You cannot put code inside the class definitions. Always put such code in the constructor. That's what they are here for.
2) You don't need a class for everything. This is not Java. Sometimes it's simpler to use functions instead.
3) A class name is neither a variable nor an array. To get an array of class objects, use:
classname varname[numberOfElements];
for example
horse horses[10];
This is by far the most common error in you program.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 06:41 AM
#16
For the new source:
You pass reference parameters just as would pass normal parameters. No & or something, this is all done at the time of declaration.
You didn't correct the horse[] failure in the raceway constructor.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 06:42 AM
#17
Transcendental: It is legal to not declare constructors//destructors. The compiler will create one that doesn't take arguments and does nothing.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 06:45 AM
#18
Thread Starter
Lively Member
thanks again!
Thanks again bee,
if you could explain it with the code i posted, i.e. make the change and repost it it would be very greatl appreciated! i kind of get what you mean but if you could change it i would understand a lot better.
thanks!
-
Nov 7th, 2001, 07:12 AM
#19
Ok. My last upload contains some corrections. e.g. service.h contains the #ifndef thing. Others come soon. (After lunch )
Last edited by CornedBee; Nov 7th, 2001 at 07:15 AM.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 07:39 AM
#20
Thread Starter
Lively Member
hehe, after lunch. I'm thinking about havin an early early early lunch, it's about 11:30pm here at the moment.
See there's a big difference between Austria and Australia, there in completely different time zones! (I read your profile, hopefully some americans will read this too, hehe).
Oh, and I was born in Australia and the last time i saw a kangaroo would have been about 5 years ago, when i last went camping out in a national park.
-
Nov 7th, 2001, 07:47 AM
#21
Yeah, it would be pretty unusual to see a kangaroo hopping through the streets of a city...
But I have seen kangaroos lately - in our local zoo
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 08:02 AM
#22
Do you want the ++ operator of time as postfix or prefix?
Code:
int i = 1;
i++; // postfix
++i; // prefix
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 7th, 2001, 08:06 AM
#23
Thread Starter
Lively Member
-
Nov 7th, 2001, 08:26 AM
#24
I got it down to 3 errors. The problem is that the bookmaker and gambler objects are members of raceway, sothey cannot be accessed in track::start_race. A solution would be to make those objects global, but I'll leave that up to you.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|