Results 1 to 24 of 24

Thread: basic c++ question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    Question 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.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  3. #3
    Zaei
    Guest
    The Time class must be defined above any code that uses it. So:
    Code:
    class Time { ... };
    
    class track { ... };
    ...will be just fine.

    Z.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121
    on the
    Time timer;
    line

  5. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    How come you have no class constructor and destructor?

    Is this allowed? Any C++ experts can explain?
    I'm a VB6 beginner.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121
    Hi Zaei,

    can you explain what you mean in more detail?

    Thanks.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    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.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121
    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.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    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....

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    new source

    here's the new source, so close to being complete!

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    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!

  19. #19
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121
    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.

  21. #21
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  22. #22
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121
    post

  24. #24
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width