logo
down
shadow

call method from a function pointer


call method from a function pointer

By : Scott Rowland
Date : October 24 2020, 06:10 AM
around this issue check is not a static member of Command - it's a member of *i - so you should use the normal member access syntax, i->check.
Also, the If instance you can call the member function on is *this.
code :
(this->*(i->check))(i->pattern, result)
class If
{
public:
    using CommandFunction = bool (If::*)(const string&, const string&);
    // Alternative: typedef bool (If::*CommandFunction)(const string&, const string&);
    struct Command {
        string pattern;
        CommandFunction check;
    };
    If() {
        Command command;
        command.check = &If::check_true;
        m_commands.push_back(command);
    }
    bool call(CommandFunction f, const string& a, const string& b)
    {
        return (this->*f)(a, b);
    }
    int modify() {
        string result;
        for (const auto& i: m_commands) {
            if (call(i.check, i.pattern, result)) 
                return EXIT_SUCCESS;
        }
        return EXIT_FAILURE;
    }
    bool check_true(const string& pattern, const string& value) { return true; }
private:
    vector<Command> m_commands;
};


Share : facebook icon twitter icon
How to Convert Address to Function Pointer to Call Method

How to Convert Address to Function Pointer to Call Method


By : user1276575
Date : March 29 2020, 07:55 AM
may help you . I'm not sure I understand what your question is exactly, but try this:
code :
((func)pPtr)();
One class method call another one via function pointer

One class method call another one via function pointer


By : user7251862
Date : March 29 2020, 07:55 AM
wish help you to fix your issue For some reason I have to call class method from another method of the same class via function pointer. This is and example code which illustrates my question: , Your syntax is correct except that instead of
code :
method(1);
(this->*method)(1);
(*this.*method)(1);
Call base method from inherited function pointer

Call base method from inherited function pointer


By : Harper
Date : March 29 2020, 07:55 AM
it fixes the issue My base class contains a function pointer to a member function. How can I call this member function from the derived class? I want to call this function by its pointer. Here is my code so far: , You almost had it, just move the parens:
code :
void callBaseFuncViaPtr (float x,float y) { (this->*FuncPtr)(x,y);}
How to call derived method via function pointer?

How to call derived method via function pointer?


By : Anrzou
Date : March 29 2020, 07:55 AM
this will help You can get rid of the first overload, because the more generic one covers all its use cases.
P.S. This appears to be a (much less generic) re-implementation of std::invoke. You might use that instead, if you have access to C++17:
code :
std::invoke(&foo::method, f);
How to call a method through a function pointer?

How to call a method through a function pointer?


By : user2834409
Date : March 29 2020, 07:55 AM
will be helpful for those in need Methods do not bind the self argument, but you can get access to the methods via their fully qualified names and you can save them in a function pointer if you like. Later on, when you invoke the function pointer you have to provide the self argument yourself:
code :
struct Foo {
    var: i32,
}

impl Foo {
    fn method(&mut self, value: i32) {
        self.var += value;
        println!("var = {}", self.var);
    }
}

fn main() {
    let mut foo = Foo { var: 11 };
    let func_ptr = Foo::method;
    func_ptr(&mut foo, 12);
}
let func_ptr: fn(&mut Foo, i32) = Foo::method;
let func_ptr: &Fn(&mut Foo, i32) = &Foo::method;
Related Posts Related Posts :
  • Compiler error when overriding virtual methods
  • What is the point of function pointers?
  • Which is faster in memory, ints or chars? And file-mapping or chunk reading?
  • ISO file in C++
  • Expected Class-name before { token
  • Can I trust floats or doubles representing integers to retain precision?
  • Qt execute multiple get with QNetworkAccessManager
  • Big and Little endian question
  • Visual Studio 2008 compiles anything in C++ file?
  • C++ pointer to functions, Beginner Question
  • Fastest algorithm for primality test
  • Passing array of pointers to another class
  • Handling macro redefinition without modifying .h files ... C / C++ language
  • Implement SSL with SSPI: How to start?
  • Creating a simple VS2008 visualizer inside autoexp.dat (problem with casting)
  • C++ - Unicode Newline
  • Program crashing with 'std::out_of_range' error
  • Use signed or unsigned char in constructing CString?
  • Parallel execution policies in C++ 17
  • C++ Class Templates (Queue of a class)
  • Convert image into useable byte array in C?
  • pointer to preallocated memory as an input parameter and have the function fill it
  • Animated Image in Win32
  • error on compiling statically linked library created in Qt
  • How to easily pass a very long string to a worker process under Windows?
  • Can a class add friend classes at runtime in C++?
  • C++ priority queue in ascending order by specific method for objects
  • Initialize and declare dynamically multiple variables of random entities in a loop in C++
  • Serializing, integer without libaries , getting weird results
  • Function pointers with default parameters in C++
  • Compilation errors with RapidXML
  • Bad_alloc exception when using new for a struct c++
  • count specific things within a code in c++
  • How to extract 48*48 icon image from resource of an executable file?
  • C++ Convert string (or char*) to wstring (or wchar_t*)
  • C++ include .h includes .cpp with same name as well?
  • Any way in C++ to forward declare a function prototype?
  • boost graph adjacency_list, retrieving a node's parents
  • Copy method optimization in compilers
  • what the problem in this program? it doesn't use the second number, and doesn't print the last line?
  • Need to format character precedence in Strings
  • Cross-Platform Camera API
  • sizeof continues to return 4 instead of actual size
  • String search algorithm used by string::find() c++
  • Two-phase lookup: can I avoid "code bloat"?
  • Strongest cipher available to use with C/C++?
  • Why does my program occasionally segfault when out of memory rather than throwing std::bad_alloc?
  • Firefox XULRunner or TriXul?
  • Does GetSystemInfo (on Windows) always return the number of logical processors?
  • Where is the difference between these code? Shouldn't output be the same?
  • What does it mean mean by "Expected a statement" in C++
  • keybd_event is not working right =(
  • What native C++ profiling tool do you suggest?
  • how to copy char * into a string and vice-versa
  • C++ write to front of file
  • Delphi conversion of C++ header for DVP7010B video card DLL?
  • I keep Getting Control reaches end of non-void function. What am I doing wrong?
  • How to have struct members accessible in different ways
  • Am I abusing Policies?
  • Modern equivalent of BoundsChecker for Visual Studio 2008
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk