Results 1 to 6 of 6

Thread: C++ help please

  1. #1
    Senior Member kasavien's Avatar
    Join Date
    Aug 2005
    Location
    St. Albans
    Posts
    1,829
    Thanks
    145
    Thanked
    104 times in 49 posts

    C++ help please

    Hi all, i'm working on my third year dissertation which involves the further development of someone else's application i've come across a line of code that i just can't decipher and it isn't commented so i would appreciate any help if someone could tell me what it's doing. The code is below

    float CurB = mEntityActionTables->Contains( B->Type ) ? dynamic_cast<EntityActionTable*>( mEntityActionTables->Item[B->Type] )->Values[mDesire] : 0;

    mEntityActionTables is a hashtable, i understand the if part is checking if there's an Entity of Type B in the table but i don't know what what is being assigned to CurB as a result. Hopefully that makes some vague kind of sense.

    Many Thanks

    Andy

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Values[mDesire] if it cotains an entity, zero if not.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Senior Member kasavien's Avatar
    Join Date
    Aug 2005
    Location
    St. Albans
    Posts
    1,829
    Thanks
    145
    Thanked
    104 times in 49 posts
    Awesome!!!! now you've said that i've just realised that ( mEntityActionTables->Item[B->Type] ) is cast as an EntityActionTable, don't know what i thought before, thanks again

    Andy

  4. #4
    Lovely chap dangel's Avatar
    Join Date
    Aug 2005
    Location
    Cambridge, UK
    Posts
    8,398
    Thanks
    412
    Thanked
    459 times in 334 posts
    • dangel's system
      • Motherboard:
      • See My Sig
      • CPU:
      • See My Sig
      • Memory:
      • See My Sig
      • Storage:
      • See My Sig
      • Graphics card(s):
      • See My Sig
      • PSU:
      • See My Sig
      • Case:
      • See My Sig
      • Operating System:
      • Windows 10
      • Monitor(s):
      • See My Sig
      • Internet:
      • 60mbit Sky LLU
    I use the
    <value> = <some condition> ? <if condition TRUE> : <if condition false>
    stuff a fair bit but it can make things hard to read (as doesn't help with the addition of dynamic_cast in this case).

    yamangman is right and i'm assuming that Values[] is an array of floats too.
    Last edited by dangel; 11-04-2007 at 04:05 PM. Reason: bunnies!
    Crosshair VIII Hero (WIFI), 3900x, 32GB DDR4, Many SSDs, EVGA FTW3 3090, Ethoo 719


  5. #5
    Senior Member kasavien's Avatar
    Join Date
    Aug 2005
    Location
    St. Albans
    Posts
    1,829
    Thanks
    145
    Thanked
    104 times in 49 posts
    I agree that that form of if statement is hard to decipher, it's not what i would normally use, i prefer the code i write to be self commenting as much as possible. But the problem is i didn't write this so i am left to try and figure it out and alter it to what i need to achieve. Values[] is an array of floats too

    Thanks

    Andy

  6. #6
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    dynamic_cast<> and templates in general can end up as poor. buggy, and unreadable code, if you find out you can do without it, do so.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •