no matching function with function pointer as arguments

Hello,

I'm trying to define a class with LuaBridge.

There is a C++ class called Entity that has a member setPosition(float,float,float).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  luabridge::getGlobalNamespace(lua_state)
        .beginNamespace("Werner3D")
            .beginClass<Werner3D::Entity>("Entity")
                .addFunction<void(*)(float,float,float)>("setPosition", &Entity::setPosition)
            .endClass()
        .endNamespace();

// addFunction is defined as this:
template <class MemFn>
    Class <T>& addFunction (char const* name, MemFn mf)
    {
      CFunc::CallMemberFunctionHelper <MemFn, FuncTraits <MemFn>::isConstMemberFunction>::add (L, name, mf);
      return *this;
    }

// setPosition is defined as
void setPosition(float x, float y, float z){
        transform.setOrigin(btVector3(x,y,z));
    }


The error:
No matching member function for call to 'addFunction'
LuaBridge/detail/Namespace.h:794:16: Candidate function [with MemFn = void (*)(float, float, float)] not viable: no overload of 'setPosition' matching 'void (*)(float, float, float)' for 2nd argument

This is XCode 5 on OSX. I'm probably overlooking something obvious, but I have only limited experience with function pointers. Can anyone see the error?
If you're wanting to call a function associated with an instance in this way, you may need to pass a reference to this instance.
Normally I should not need an instance of Entity when defining a lua class.

I used it successfully in the past, I just can't get this code to compile for some reason.

EDIT:
I guess I don't fully master the syntax of function pointers. Changed the call to this, it compiles now:

.addFunction<void(Werner3D::Entity::*)(float,float,float)>("setPosition", (void(Werner3D::Entity::*)(float,float,float)) &Werner3D::Entity::setPosition)

The compiler was appearently also confused because this member function in overloaded (one takes a vector3, the other takes 3 floats).
Last edited on
Topic archived. No new replies allowed.