2011-08-09 42 views
0

我試圖註冊從Irrlicht的以下功能,dimension2df:註冊Irrlicht的班級分成angelscript給<懸而未決的重載函數類型>

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

這裏是我的C++代碼以註冊重載的運算符=到angelscript:

r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asFUNCTIONPR(operator==, (dimension2df&), bool),asCALL_CDECL_OBJFIRST); assert(r >= 0); 

在編譯時,得到以下錯誤消息:

E:\pb\main.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); 

我試圖儘可能地效仿的榜樣,但這個問題確實讓我難住了。

回答

1

我已經想通了,這裏是正確的代碼:

r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asMETHODPR(dimension2df, operator==, (const dimension2df&) const, bool),asCALL_THISCALL); assert(r >= 0); 
相關問題