Thread: string as a variable name

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    50

    Question string as a variable name

    Hi everyone! I am a new user and I have, maybe, a big question. Is it possible to do a function that takes as argument the name of the variable that i want to initialize? It is something like this

    Code:
    #include<...>
    ...
    void initialize(char name, int length)
    {
      int *name, init_name[length];
      name=&ini_name[0];
    }
    is this impossible?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, but a function-style macro might work. What exactly are you trying to do?
    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
    May 2010
    Posts
    50
    Quote Originally Posted by laserlight View Post
    No, but a function-style macro might work. What exactly are you trying to do?
    I want to do a small function that does the task I have written. It is just to don't have to type every time the pointer's name, the array's name and to initialize the pointer :-)
    Can you give me an example of function-style macro because I have never heard about this
    Last edited by violatro; 05-31-2010 at 09:58 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by violatro
    It is just to don't have to type every time the pointer's name, the array's name and to initialize the pointer
    That sounds pointless, e.g.,
    Code:
    int init_name[length];
    int *name = init_name;
    Quote Originally Posted by violatro
    Can you give me an example of function-style macro because I have never heard about this
    You could just read about macros in general, and you will learn about them.
    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
    May 2010
    Posts
    50
    Quote Originally Posted by laserlight View Post
    That sounds pointless, e.g.,
    Code:
    int init_name[length];
    int *name = init_name;
    I am a little lazy :-) and also I want a "clean" code
    Quote Originally Posted by laserlight View Post
    You could just read about macros in general, and you will learn about them.
    I thought that they were something different from macros! Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM