Thread: string to call function

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    7

    string to call function

    I have a function which call by

    test0.write() to write to some register

    how do I do this

    char str[7]="test";
    strcat(str, "0");

    so I can do this

    str.write()

    basically this will equal to test0.write()

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    You can't construct an object's variable name from a string and call methods on it.
    Looks like you're looking for an array of objects you can select by index.

    This is C++, BTW.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Quetzaltenango
    Posts
    82
    Quote Originally Posted by john.c View Post
    You can't construct an object's variable name from a string and call methods on it.
    I believe you can do something like that in the C preprocessor. But I don't know if it applies to C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function call Overhead and Function Call Stack
    By Alam Khan in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2014, 08:28 AM
  2. Replies: 11
    Last Post: 05-19-2009, 08:17 AM
  3. Can U Use a string to call a function
    By passy in forum C Programming
    Replies: 3
    Last Post: 08-11-2003, 10:15 AM
  4. Changing a input string to a function call?
    By cezaryn in forum C Programming
    Replies: 4
    Last Post: 07-16-2003, 02:37 PM
  5. Call a function from a string?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 08-06-2002, 04:38 PM

Tags for this Thread