You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting compilation error when I try to register member function x and y for MyVector class.
I think it's happening because of const member function overload.
#include <sol/sol.hpp>
// Small example class similar to magnum vector2
template<std::size_t size, class T>
class MyVector
{
protected:
T _data[size];
};
template<typename T>
class MyVector2 : public MyVector<2, T>
{
public:
T &x() { return MyVector<2, T>::_data[0]; }
const T &x() const { return MyVector<2, T>::_data[0]; }
T &y() { return MyVector<2, T>::_data[1]; }
const T &y() const { return MyVector<2, T>::_data[1]; }
};
int main()
{
sol::state lua;
lua.open_libraries(sol::lib::base, sol::lib::package);
using MyVec2D = MyVector2<float>;
MyVec2D my_vec;
// Gives compilation error
sol::usertype<MyVec2D> my_vec2_type = lua.new_usertype<MyVec2D>("MyVec2D",
sol::constructors<MyVec2D()>());
my_vec2_type["x"] = &MyVec2D::x;
return 0;
}
There are basically multiple possible definitions and you need to choose one.
You can use a static cast or a sol helper function sol::resolve to specify the one you want.
I am getting compilation error when I try to register member function x and y for MyVector class.
I think it's happening because of const member function overload.
The error I am getting are
I tried multiple things to make it work, but did not work. Is there any way to register the functions MyVector2::x() ?
The text was updated successfully, but these errors were encountered: