rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.12k stars 430 forks source link

How do I call an overloaded function #319

Closed straywriter closed 3 years ago

straywriter commented 3 years ago

windows 10 vs 2019 I have the following code

#include <rttr/registration>
using namespace rttr;
#include <iostream>
struct MyStruct
{
  MyStruct() {};
  void func() { std::cout << 0; }
  void func(double a) { std::cout << 1; };
  int  data;
};

RTTR_REGISTRATION
{
  registration::class_<MyStruct>("MyStruct")
  .property("data",  &MyStruct::data)
  .method("func",  static_cast <void(MyStruct::*)()>( &MyStruct::func))
  .method("func",  static_cast <void(MyStruct::*)(double)>( &MyStruct::func));

}

#include <iostream>
int main()
{
  MyStruct obj;
  method meth = type::get(obj).get_method("func");
  meth.invoke(obj);
  meth.invoke(obj,1.);
}

meth.invoke(obj,1.); This code cannot be called How do I call an overloaded function