Im learning C++ at the moment, and am having some issues with casting pointers. In the first place I am not sure that what I am trying to do is what I want to do..
I am trying to take a function that can return the appropriate pointer to various method pointers based on string parameters, and to then use the method pointer.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef void* (*plugin_function)(void*);
static class Plugin
{
public:
static bool doBoolStuff(){
return true;// A Simple function that returns true
}
};
void* getFunction(string pluginName, string functionName)
{
if(pluginName =="Bool"){
return &Plugin::doBoolStuff;
//If the string is right it should return a method pointer.
//I think that void* has the ability to point to anything, I am trying
//to use that functionality to create a system where I am able to set
//some parameters and get the appropriate method pointer.
}else{
return NULL;
}
}
int main(int argc, _TCHAR* argv[])
{
void* pluginFunction;
pluginFunction = getFunction("Bool","");
if(pluginFunction == &Plugin::doBoolStuff)cout<<"CastSuccesful!"<<endl;
//This section right here is where my code is breaking.
//
// IntelliSense: expression preceding parentheses of apparent call must have
//(pointer-to-) function type
//c:\Users\Walter\Dropbox\Inscription\MethodCasting\MethodCasting\MethodCasting.cpp
//MethodCasting
cout << "Bool function ->"<< pluginFunction()<<endl;
cout << "--------------------------------"<<endl;
system("pause");
}
Any feedback would be helpful.