Thread: Multiple reference

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    61

    Multiple reference

    Hi Everyone!Can I a have one pointer with two reference in it. Here's what I've got.

    Code:
    char* c;
    char x='x' , y='y';
    c = &x;
    c = &y;
    -- or --

    Code:
    char* c[2];
    char x='x' , y='y';
    c[0] = &x;
    c[1] = &y;
    If it's possible I want to apply it to make AST.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, in your first code snippet, your pointer will either refer (as in point) to x or to y, but not both at the same time. In your second code snippet, you have an array of two pointers, hence one pointer can refer to x and the other refer to y.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    61
    Is there any way to make it possible? I want to make a node to point to N-nodes.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Create a node structure with a pointer that will point to the first node structure in a dynamic array of node structures.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    61
    Code:
    typedef struct Tree {
        char* info;
        struct Tree* children[MAX_LENGTH];
    } Tree;
    Is this correct??
    Last edited by programmerc; 08-20-2014 at 01:56 AM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That is not quite what I had in mind, but it certainly is a viable alternative.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    61
    Quote Originally Posted by laserlight View Post
    That is not quite what I had in mind, but it certainly is a viable alternative.
    Can you tell me the code?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Use your idea. It can work.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Dec 2012
    Posts
    61
    Okay, Thanks haha

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-21-2014, 04:14 PM
  2. Reference to Reference, Pointer to Reference....
    By hqt in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2011, 06:21 AM
  3. multiple definition, undefined reference to
    By jeffeklund in forum C++ Programming
    Replies: 11
    Last Post: 06-08-2005, 08:01 AM
  4. Linking multiple source files: Undefiled Reference to...
    By Inquirer in forum C++ Programming
    Replies: 4
    Last Post: 05-03-2003, 05:47 PM
  5. Replies: 1
    Last Post: 05-01-2003, 02:52 PM

Tags for this Thread