Linked Questions

0 votes
1 answer
312 views

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, ...
user3842642's user avatar
2 votes
0 answers
142 views

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 ...
yayuj's user avatar
  • 2,504
0 votes
0 answers
70 views

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&...
user19899551's user avatar
345 votes
24 answers
638k views

Compiling the following code gives the error message: type illegal. int main() { // Compilation error - switch expression of type illegal switch(std::string("raj")) { case&...
yesraaj's user avatar
  • 48.3k
0 votes
1 answer
1k views

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) { ...
Anees's user avatar
  • 87
0 votes
2 answers
1k views

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&...
noClueAboutWhatIMDoing's user avatar
-1 votes
1 answer
1k views

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 ...
user644361's user avatar
0 votes
1 answer
1k views

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 ...
Hugo Rodrigues's user avatar
0 votes
2 answers
649 views

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) { ...
Alan Valejo's user avatar
  • 1,315
1 vote
2 answers
586 views

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 ...
Krowk's user avatar
  • 46
2 votes
1 answer
298 views

I'm storing a pointer to a function as a string: //callback = std::function<void()> callback std::stringstream cbPtrToString; cbPtrToString << &callback; std::string prtString = ...
Kmcgurty's user avatar
2 votes
3 answers
69 views

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 ...
J.dd's user avatar
  • 157
-1 votes
2 answers
92 views

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 ...
Logic's user avatar
  • 11
0 votes
1 answer
112 views

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 ...
sancho.s ReinstateMonicaCellio's user avatar
1 vote
0 answers
52 views

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 ...
Anees's user avatar
  • 87