I have a method with this signature:

const std::string GameObject::GetName()

And then I try to bind it with this line:

.addFunction("getName", &GameObject::GetName)

When I try to compile, this error comes up:

Error C2440 '=': cannot convert from 
'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> *' 
'void *'    

The error comes from here:

\include\luabridge\detail\Userdata.h, line: 354 

Here is a snippet from the Userdata.h

  inline T* getObject ()
    // If this fails to compile it means you forgot to provide
    // a Container specialization for your container!
    return reinterpret_cast <T*> (&m_storage [0]);

    Used for placement construction.
  UserdataValue ()
    m_p = getObject(); //Line 354

I can use const, and const & std::string as parameters, in those cases there are no errors.

Why does this error occur? How could I fix this?

Thanks in advance!


Sounds like a bug in LuaBridge, so you should report it.

As for fixing your project, just remove the const, it doesn't make sense anyway since you're returning a value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.