Thread: semantics question

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    27

    semantics question

    hi there

    I'm looking for a bit of semantics help. I know what I want to do, but don't know what its called so I can't really learn how to do it :P

    I have four classes:

    Snake
    PlayerSnake
    AISnake
    Food

    PlayerSnake and AISnake are derived classes of Snake. The food class needs to be able to access some of the attributes of PlayerSnake and AISnake (the coordinates of there first nodes).

    Is there a way to have a class access another attributes without inheritance? if so what's this called?

    will a simple 'get_x' and 'get_y' work? if so, what would go into those functions?

    thanks for the help, I'm still quite new to coding

    cheers

    ES

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about a Snake method called 'snake::eats(position)', which returns true if the snake is able to eat at the indicated position?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  2. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  3. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM