Thread: C++ Question

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    18

    Unhappy C++ Question

    I have a question and a friend tells me that this is not possible. Please prove him wrong and help me out in the process. OK first I am working on a strictly text based chess game. Say the variable PIECE is an array of 4 characters where the first three letters is the name of the object and the last letter is the subscript to be used. I know how to seperate the first three letters from the last but can I use the first 3 as the object name to be used? It's kind of hard to explain. Can I make a function that is passed a variable piece. Say piece = "p2p0" then the function would do this p2p[0].x = x; p2p[0].y = y;. Any help is greatly appreciated and I hope you can understand what I'm trying to say. You can message me on AOL instant messager, or email me at [email protected], or just reply back here. Thanks again.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Your "friend" wouldnt happen to be a lecturer/tutor/teacher huh?

    If this (as I guess) is homework, then we dont help see - http://www.cprogramming.com/cboard/f...p?s=&forumid=3

    <Side Note>
    It amazing that so many people seem to have these in depth discussions with friends about whats possible or not in programming, and then they go out to find help to prove the other wrong......There must be something wrong with me as all my friends and I discuss centres around either women or humour.....
    </Side Note>

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post a specific question.

    Kuphryn

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    18
    it is a specific question, read it again, and no it's not a teacher. I am working on a chess program and this question (if possible) would help me out. Now I don't know why you and your friends only talk about girls but not everyone is like you. I have a friend who is fairly knowlegable and said it wasn't possible. I thought it had to be so I asked here. Trust me it's not for a teacher. It's not really even that in depth of a question I just typed alot to make sure I got the question across. pass a function an array of 4 characters (PIECE). Say PIECE = "p2p0" somehow make it into this command p2p[0].x = x; And don't use a bunch of if's because that is what I am using now. Thanks again.
    Be yourself for those who mind don't matter, and those who matter don't mind.

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    is it really necessary to use an array?
    It would probably be easier to accept a string and parse it
    Monday - what a way to spend a seventh of your life

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    18
    I'm open for any ideas that get the job done. If it's easier to use a string then explain it. The way it's coming in is not the problem.
    Be yourself for those who mind don't matter, and those who matter don't mind.

  7. #7
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    It is impossible to convert a string to a variable name.

    The compiled program doesn't know about variable names.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    18
    thanks sang. If this makes any difference, it is not creating variables just using PIECE to find which object to change the values of. The objects already exist. Does that make any difference?
    Be yourself for those who mind don't matter, and those who matter don't mind.

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    18
    Do you think you could either find me a link to an example or explain how I would implement a very simple example? Thanks.
    Be yourself for those who mind don't matter, and those who matter don't mind.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 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