Hi all,
I'm a newcomer. I'm using SqPlus for binding my c++ code.When binding an overloaded member function, I got a strange result. Here is the c++ code:
class MyOverload
{
public:
MyOverload() : value(0) {}
void Inc() { value++; }
void Inc(int v) { value += v; }
void Dec() { value--; }
void Dec(int v) { value -= v; }
void Mult(int v) { value *= v; }
int value;
};
DECLARE_INSTANCE_TYPE(MyOverload)
Binding using SQClassDef:
SQClassDef<MyOverload>(_T("MyOverload"))
.var(&MyOverload::value, _T("value"))
.overloadFunc<void (MyOverload::*)(void)>(&MyOverload::Dec, _T("Dec"))
.overloadFunc<void (MyOverload::*)(int)>(&MyOverload::Dec, _T("Dec"))
.overloadFunc<void (MyOverload::*)(void)>(&MyOverload::Inc, _T("Inc"))
.overloadFunc<void (MyOverload::*)(int)>(&MyOverload::Inc, _T("Inc"))
.func(&MyOverload::Mult, _T("Mult")) ;
Squirrel test script:
local ov = MyOverload();
print("Initial Value:" + ov.value);
ov.Inc();
print("Value after Inc:" + ov.value);
ov.Inc(10);
print("Value(10):" + ov.value);
ov.Dec();
print("Value after Dec:" + ov.value);
ov.Dec(30);
print("Value(30):" + ov.value);
ov.Mult(10);
print("Value after Mult(10)" + ov.value);
Result:
Initial Value:0
Value after Inc:1
Value(10):11
Value after Dec:12
Value(30):42
Value after Mult(10)420
It seems that the if the member function has same type of argument(s), the latest function will be called. I've changed binding order(Inc followed by Dec) and I got an opposite result.
Any suggestions?