将 irrlicht 类注册到 angelscript 中会给出<未解析的重载函数类型>
Registering irrlicht class into angelscript gives <unresolved overloaded function type>
我试图注册以下函数从Irrlicht, dimension2df:
template <class U>
dimension2d<T>& operator=(const dimension2d<U>& other)
{
Width = (T) other.Width;
Height = (T) other.Height;
return *this;
}
这是完整的源文件:http://irrlicht.sourceforge.net/docu/dimension2d_8h_source.html
下面是我在angelscript中注册重载操作符=的c++代码:
r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asFUNCTIONPR(operator==, (dimension2df&), bool),asCALL_CDECL_OBJFIRST); assert(r >= 0);
在编译后,我得到以下错误消息:
E:pbmain.cpp|295|error: invalid static_cast from type '<unresolved overloaded function type>' to type 'bool (*)(irr::core::dimension2df&)'|
查看文档,它描述了注册操作符函数的方法:
struct Vector3
{
Vector3();
Vector3(const Vector3 &other);
Vector3(float x, float y, float z);
Vector3 &operator=(const Vector3 &other);
Vector3 &operator+=(const Vector3 &other);
Vector3 &operator-=(const Vector3 &other);
Vector3 &operator*=(float scalar);
Vector3 &operator/=(float scalar);
friend bool operator==(const Vector3 &a, const Vector3 &b);
friend bool operator!=(const Vector3 &a, const Vector3 &b);
friend Vector3 operator+(const Vector3 &a, const Vector3 &b);
friend Vector3 operator-(const Vector3 &a, const Vector3 &b);
friend Vector3 operator*(float s, const Vector3 &v);
friend Vector3 operator*(const Vector3 &v, float s);
friend Vector3 operator/(const Vector3 &v, float s);
float x;
float y;
float z;
};
r = engine->RegisterObjectMethod("vector3", "bool opEquals(const vector3 &in) const", asFUNCTIONPR(operator==, (const Vector3&, const Vector3&), bool), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
我尽量照着例子做,但是这个问题真的把我难住了。
我已经弄清楚了,这里是正确的代码:
r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asMETHODPR(dimension2df, operator==, (const dimension2df&) const, bool),asCALL_THISCALL); assert(r >= 0);
相关文章:
- 继承函数的重载解析
- 你能重载对象变量名本身返回的内容吗
- 从父命名空间重载类型
- 使用C++中的模板和运算符重载执行矩阵运算
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 重载操作程序时出错>>用于类中的字符串 memebr
- 一个关于在C++中重载布尔运算符的问题
- 不同翻译单元中不可重载的非内联函数定义
- 为什么使用SFINAE而不是函数重载
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- 将重载的成员函数传递给函数模板
- c++:可变模板和函数重载
- 重载元组索引运算符-C++
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 重载==不适用于二进制树
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 重载运算符new[]的行为取决于析构函数
- 正在尝试重载二进制搜索树分配运算符
- 重载Singly Linked List中的赋值运算符
- 取消引用运算符不能重载