Linked Questions
15 questions linked to/from How to call a function by its name (std::string) in C++?
0 votes
1 answer
312 views
How does char pointer reference to function name in C++ [duplicate]
I am very kindergartener to C++. Hope someone can help me out with my problem. Assume there is a function defined in one class. void __foo__(int x, int y){ //do something } In another class, ...
2 votes
0 answers
142 views
Calling function by its name as string [duplicate]
Is it possible to call a method by its name as string? #define callmethod(function) \ this->#function(); Just a simple example. (it doesn't work). callmethod("myfunction"); error: expected ...
0 votes
0 answers
70 views
Is there a way to call a function using the input from user c++ [duplicate]
I want to make a function call based on the input string given by the user. Example: void hello() { cout<< "print hello"; } void hello_world() { cout<<"print hello_world&...
345 votes
24 answers
638k views
Why can't the switch statement be applied to strings?
Compiling the following code gives the error message: type illegal. int main() { // Compilation error - switch expression of type illegal switch(std::string("raj")) { case&...
0 votes
1 answer
1k views
use std::string to call a function in C++11
I want to use string value to call a function. Is this possible? Can someone please show some implementation. I would appreciate it. class obj { int num1; int num2; } int func1(obj o) { ...
0 votes
2 answers
1k views
C++ How can I convert a string to enum to use it in a switch?
I have a list of commands that if a user inputs then it will call separate functions. Talking to a friend he said I should use switch, which is faster and easier to read over "if, else if, else&...
-1 votes
1 answer
1k views
Calling functions from a text file
I'm trying call fA and fB from test.txt when they're read in main.cpp while loop. test.txt fA() fB("fB") main.cpp #include <iostream> #include <fstream> #include <string> void ...
0 votes
1 answer
1k views
C++ Shell interface
I'm building an application where the interface is like a shell. The idea is to write the function name and the function is called. I saw a post in stackoverflow (see below) that explains a way to do ...
0 votes
2 answers
649 views
How to call a function by its name. An approach using STL::map and Class
Based on post How to call a function by its name (std::string) in C++?, tried to make a version using CLASS, but my approach does not work. class A { public: int add(int i, int j) { ...
1 vote
2 answers
586 views
How to call a function from an object with a std::string
Here's my issue, I would like to call the getters/setters of one of my objects, but not directly, I want to do it by using a std::string. I found this but it won't work on my case I think it is ...
2 votes
1 answer
298 views
How can I convert a pointer stored in an std::string, back into a callable function?
I'm storing a pointer to a function as a string: //callback = std::function<void()> callback std::stringstream cbPtrToString; cbPtrToString << &callback; std::string prtString = ...
2 votes
3 answers
69 views
Dynamicly setting which parameter to extract
Having structure struct Person{ Person(int a , int i):age(a),id(i){}; int age; int id; } Is it possible to pass which argument to exctract as argument in function? Something like int ...
-1 votes
2 answers
92 views
Is there a simple way to implement it in C++?
I want to implement a function that can print out the value of one member variable (for example, 'aa') of struct ('Data') by it's name. I try to use the macro definition as follows, but failed. Is ...
0 votes
1 answer
112 views
Call a class method inside a function which was passed as a string parameter
EDIT: getPropertySingle and getPropertySingle are class methods of the most base class obj2_t in a hierarchy, different from the most base class obj_t for fAggregate. This seemed irrelevant (I omitted ...
1 vote
0 answers
52 views
store pointers to such functions that can have any return type and also can have different number of parameters of any type [duplicate]
I came across this post, and it is some what I am trying to do, but "I want a map that can store pointers to such functions that can have any return type and also can have different number of ...