I have something similar to
Base.h
#ifndef BASE_H
#define BASE_H
class Base
{
virtual Base* createNew() = 0;
}
#endif
D.h
#ifndef D_H
#define D_H
#include "Base.h"
class D : public Base
{
virtual Base* createNew();
}
#endif
D.cpp
#include "D.h"
Base* D:createNew()
{
return new D();
}
main.cpp
typedef Base* (Base::*FP)(void);
#include "D.h"
void create(FP pointer)
{
//empty for now
}
int main()
{
create(&D::createNew); //This doesnt work =s?
}
I am extremely confused why this doesn’t work can anybody give me some advice on what I should be doing????
Ps. Sorry if the code doesnt run I put it there for example sakes just to show you what I was doing
There are numerous syntax problems in your code;
;.…
I think what you’re referring to though is that taking a member function pointer and passing it to a method won’t work.
The problem is that you’re taking a method that can only be called with a
Dand trying to pass it as a pointer to a function that can take aBasethat is not necessarily aD. The reverse would work, (ie passingBase::createNew()to a function taking aD::createNew()sinceBase::createNew()always exists in a D, not the other way around)