Thread: Access data in a parent class.

  1. #16
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> There is no child or parent, there is one class...

    I know that. But the OP was talking about inheritance, so I got confused about what he meant.

  2. #17
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Code:
    int minimax__depth = 0;
    
    class minimax
    {
       public:
          minimax();
          minimax *ply;
          char board[20];
          int depth;
          void look_ahead(); 
    };
    
    minimax::minimax(){
       depth = minimax__depth;
       minimax__depth++;   }
    
    void minimax::look_ahead()
    {
          }
    WORKS!!!

    But,

    Code:
    if(ply.depth == 0) Beep(2000,100);
    if(ply.ply[0].depth == 1) Beep(2000,100);
    Prog locks up.

    Code:
    if(ply.depth == 0) Beep(2000,100);
    if(ply.ply[0].depth == 1) Beep(2000,100);
    Also, locks up.

    I'm guessing that (in the ply.ply[0].depth) it's not trying to access ply's ply. Just ply.

    Renaming my lead ply to ply1 would fix that, but, not when I want to do this for an example:

    ply.ply[0].ply[2].ply[1].ply[0].depth

    What should I do now?

  3. #18
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    That doesn't make any sense. Since ply is a pointer,
    Code:
    if(ply.depth == 0) Beep(2000,100);
    if(ply.ply[0].depth == 1) Beep(2000,100);
    should not compile.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #19
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    It does though.

    I learned that a compiler will see *char_var the same as char_var[infinite].

  5. #20
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I learned that a compiler will see *char_var the same as char_var[infinite].
    ...
    My best code is written with the delete key.

  6. #21
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    What is the compiler you are using?

    ply is a pointer. To access its member you do ply->depth. Not ply.depth.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #22
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    okay using ply.ply->depth compiles but still locks up.

    Using Dev-C++.

    >> I'm guessing that (in the ply.ply[0].depth) it's not trying to access ply's ply. Just ply.

    This still remains true, how can I get around that?

  8. #23
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    You are not reading anyone replies. so... good luck with your program
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #24
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> You are not reading anyone replies. so... good luck with your program

    What do you mean I'm not reading anyone replies!!!
    I have tried your suggestions, and they DON'T WORK.
    Okay, so ply is a POINTER. Got it.
    Where does that leave me?

  10. #25
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Actually, now that I think of it, I am probably going about this whole thing the wrong way.

    Thanks for the help guys, sorry all it did was show me that I'm doing it wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc: Template class child can't directly access parent fields
    By SevenThunders in forum C++ Programming
    Replies: 11
    Last Post: 03-17-2009, 06:05 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM