billyquith / ponder

C++ reflection library with Lua binding, and JSON and XML serialisation.
http://billyquith.github.io/ponder/
Other
645 stars 95 forks source link

function call by reference not supported? #83

Open shierei opened 7 years ago

shierei commented 7 years ago

It looks like if you create a member function with a reference type, it fails to compile when you declare this class member function to Ponder. For example, suppose I add a member function as follows in the Ponder example with the person class.

void callByRef(int& a)
{
    a = 10;
}

The declaration below would not compile.

.function("callByRef", &Person::callByRef)

/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/functional:2434:5:
    note: _Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {Person&, int&}]
 function<_Res(_ArgTypes...)>::
 ^
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/functional:2434:5:
    note:   no known conversion for argument 2 from ?ponder::runtime::impl::ConvertArg<2, int&>::ReturnType {aka int}? to ?int&?

Is this documented? Why can it be supported?

-Shie-rei

shierei commented 7 years ago

I tried this out on CAMP. CAMP compiled fine but in run time, instead of doing call by reference, it behaves as call by value.

billyquith commented 7 years ago

I'll try and find some time to look at it. In the meantime I can only suggest looking at the unit tests, which are fairly extensive, and source code.

I vaguely remember something about CAMP stripping the qualifiers from argument types. Part of the problem is that it has a generic calling mechanism and possibly types get coerced/simplified so the thing you think you are referencing is not what you think it is.