Problem Overloading Function

View: New views
3 Messages — Rating Filter:   Alert me  

Problem Overloading Function

by Phlox Icon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've successfully bound an overloaded function before but this one is giving errors.

It's of the CAI_BaseNPC class. The function I'm trying to bind is the top one here.
CAI_Motor * GetMotor() { return m_pMotor; }
const CAI_Motor * GetMotor() const { return m_pMotor; }

I thought maybe it was because of missing includes or something so I put them in. Here's the code that generates the error.
#include "ai_basenpc.h"
#include "ai_motor.h"
class CAI_Motor;
....
.def( "KeyValue", (bool(CBaseEntity::*)(const char*, const char*)) &CBaseEntity::KeyValue ) // overloaded fine
.def( "GetMotor", (CAI_Motor( CAI_BaseNPC::* )(void)) &CAI_BaseNPC::GetMotor ) // generates error

There are quite a few erro messages but they're all pretty much the same after the second one.. These are the first two.
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'CAI_Motor (__thiscall CAI_BaseNPC::* )(void)'
1>        None of the functions with this name in scope match the target type
1>.\lua_luahandle.cpp(171) : error C2780: 'luabind::class_<T> &luabind::class_<T>::def(luabind::detail::operator_<Derived>)' : expects 1 arguments - 2 provided
1>        with
1>        [
1>            T=CAI_BaseNPC
1>        ]
1>        c:\HL2AITools02\src\lua\luabind-0.8.1\luabind/class.hpp(1207) : see declaration of 'luabind::class_<T>::def'
1>        with
1>        [
1>            T=CAI_BaseNPC
1>        ]

Any ideas? Thanks.

------------------------------------------------------------------------------

_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: Problem Overloading Function

by James Porter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Phlox Icon wrote:
> CAI_Motor * GetMotor() { return m_pMotor; }
[snip]
> .def( "GetMotor", (CAI_Motor( CAI_BaseNPC::* )(void))
> &CAI_BaseNPC::GetMotor ) // generates error

You're returning a CAI_Motor* but your cast says you're returning a
CAI_Motor.

- Jim


------------------------------------------------------------------------------
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: Problem Overloading Function

by Phlox Icon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Holy crap. I don't know how I overlooked something so obvious. I'm quite embarrassed to have sent this now :S

But thank you very much, James. Well spotted. I owe you one. :D

------------------------------------------------------------------------------

_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user