Type checking

This is a discussion on Type checking within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by h3ro I cant. They have to be in the same array. There will never be a mix ...

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by h3ro View Post
    I cant. They have to be in the same array.


    There will never be a mix between then and never more then two car types. The project is done, adding up scores at the end is the only part that is left
    There are a lot of things you could do without interrogating the type. As Elysia suggested, keep them (smart pointers to them) in separate arrays as well as the main array. Or add a reportTime() member function, and have each type report to a singleton object that stores the total time - one for raceCars, one for crapCars.

    Or if there are only ever going to be two types, maybe interrogating the type isn't so bad, but I'd still feel dirty doing it.

  2. #17
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Or if there are only ever going to be two types, maybe interrogating the type isn't so bad, but I'd still feel dirty doing it
    Same here. I want for the easy solution for this, I now have a virtual function called getType(). Not so sexy, but it works.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. Data type checking?
    By Trauts in forum C++ Programming
    Replies: 2
    Last Post: 02-09-2003, 04:24 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. Type checking
    By Araenor in forum C Programming
    Replies: 10
    Last Post: 08-29-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21