Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
G

G_urr_A

@G_urr_A
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Polymorphic pointer points to what?
    G G_urr_A

    Hmm.... Since I've already started a thread, I guess I might as well put it to good use... ;-) I've implemented an ugly hack now. In the code where I give bullets their position and speed, I first find the ship that fired them in ObjectList (which is the vector of *base_class that I've mentioned), then get some data from the ship object. The thing is, I need to access methods that are specific to the CShip class, but I've only got a pointer to base_class to handle it. What I do now is the following: CShip *temp; temp = (CShip*)(void*)ObjectList.at(i); I cast to void* and then to the data type I need. Anything but this explicit casting produces errors, since the compiler doesn't realize that I've checked (using typeid) that what I'm handling is really a CShip object. This solution is really ugly, IMO. There should be a good way to do this, but I can't figure it out (I'm kind of new to OO).

    C / C++ / MFC game-dev graphics question learning

  • Polymorphic pointer points to what?
    G G_urr_A

    I've ended up using typeid now. And of course I'm using the best possible design. Not. It's grown slightly too messy for my tastes by now, and it'll probably get worse. The whole thing is a school project in which I have to cooperate with another guy. We've implemented support in some places for features that haven't been implemented, we did not think everything through before we started writing, and we don't really share a common concept of what OO is, so the code is quite messy. I'd love to rewrite the whole thing, but we're expected to present the stuff to our teacher this friday, and we're expected to understand all the code (he needs to understand "my parts"), and he's out of town, coming back thursday evening. So, a rewrite isn't an option right now. But, thanks a lot to everyone for the input! We got my problem solved, and I got some other good info on what not to do next time. Now I just need to finnish this stuff...

    C / C++ / MFC game-dev graphics question learning

  • Polymorphic pointer points to what?
    G G_urr_A

    I'm programming a little game, an Asteroids clone. I need to do some collision detection. In order to determine what should happen when two objects collide, I need to know which types of objects they are. I've got a few different classes, one for the player ship, one for asteroids and another for the bullets that the player can shoot. All of these are children of a base class containing some generic physics code. I've got a vector of *base_class which keeps track of all objects, meaning that regardless of whether the object is of class ship or class asteroid or whatever, it is stored and accessed through a vector of *base_class. What I need to do now is to go through this vector and find objects of certain types, i.e. find all asteroids. I could of course just add another member variable and set it accordingly, but I was wondering if there is a way to determine what type of object the pointer is pointing at. Does anyone have any suggestions?

    C / C++ / MFC game-dev graphics question learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups