C ++ 2 Overloads有类似的Conversions-Game Project

时间:2013-10-01 02:46:14

标签: c++ visual-c++

错误:

Source\_Interface\WndTaskBar.cpp(9681) : error C2666: 'CTexture::RenderRotate' : 2 overloads have similar conversions

    Source\_Common\2DRender.h(245): could be 'void CTexture::RenderRotate(C2DRender *,CPoint,FLOAT,BOOL,DWORD,FLOAT,FLOAT)'

    Source\_Common\2DRender.h(240): or       'void CTexture::RenderRotate(C2DRender *,CPoint,FLOAT,DWORD,FLOAT,FLOAT)'
            while trying to match the argument list '(C2DRender *, CPoint, float, int, float, float)'

    Source\Source\_Interface\WndTaskBar.cpp(9682) : error C2666: 'CTexture::RenderRotate' : 2 overloads have similar conversions

    Source\_Common\2DRender.h(245): could be 'void CTexture::RenderRotate(C2DRender *,CPoint,FLOAT,BOOL,DWORD,FLOAT,FLOAT)'

    Source\_Common\2DRender.h(240): or       'void CTexture::RenderRotate(C2DRender *,CPoint,FLOAT,DWORD,FLOAT,FLOAT)'
            while trying to match the argument list '(C2DRender *, CPoint, float, int, float, float)'

WndTaskBar.cpp

9679    if( ( m_nActionSlot > 0 )&&( g_WndMng.m_pWndTaskBar->m_nExecute > 0 ))
9680    {
9681      SlotRt2->RenderRotate( p2DRender, CPoint(0,0), RotateSLOT, 255, 1.0f, 1.0f );
9682      SlotEffect2->RenderRotate( p2DRender, CPoint(0,0), RotateSLOT, m_nFlashAlpha[0], 1.0f, 1.0f );
9683    }
9684    else
9685    {
9686      SlotRt2->Render( p2DRender, CPoint(0,0), 255 );
9687      SlotEffect2->Render( p2DRender, CPoint(0,0), 0);
9688    }

2DRender.h(其他几行)

227 //BOOL LoadTextureFromRes( LPDIRECT3DDEVICE9 pd3dDevice, LPCTSTR pFileName, D3DCOLOR d3dKeyColor, BOOL bMyLoader = FALSE );
228 void Render( C2DRender* p2DRender, CPoint pt, DWORD dwBlendFactorAlhpa = 255 ) {
229     p2DRender->RenderTexture( pt, this, dwBlendFactorAlhpa ); 
230 }
231 void Render( C2DRender* p2DRender, CPoint pt, CPoint pt2, DWORD dwBlendFactorAlhpa = 255, FLOAT fscalX = 1.0, FLOAT fscalY = 1.0 ) {
232     p2DRender->RenderTextureEx( pt, pt2, this, dwBlendFactorAlhpa, fscalX, fscalY ); 
233 }
234 void RenderEx2( C2DRender* p2DRender, CPoint pt, CPoint pt2, DWORD dwBlendFactorAlhpa = 255, FLOAT fscalX = 1.0, FLOAT fscalY = 1.0, D3DCOLOR color = 0 ) {
235     p2DRender->RenderTextureEx2( pt, pt2, this, dwBlendFactorAlhpa, fscalX, fscalY, color ); 
236 }
237 void RenderScal( C2DRender* p2DRender, CPoint pt, DWORD dwBlendFactorAlhpa = 255, FLOAT fscalX = 1.0, FLOAT fscalY = 1.0 ) {
238     p2DRender->RenderTexture( pt, this, dwBlendFactorAlhpa , fscalX, fscalY ); 
239 }
240 void RenderRotate( C2DRender* p2DRender, CPoint pt, FLOAT fRadian, DWORD dwBlendFactorAlhpa = 255, FLOAT fscalX = 1.0, FLOAT fscalY = 1.0 ) {
241     p2DRender->RenderTextureRotate( pt, this, dwBlendFactorAlhpa , fscalX, fscalY, fRadian ); 
242 }
243
244 //added by gmpbigsun : ȸÀüÃà º¯°æ°¡´É ( center or start point )
245 void RenderRotate( C2DRender* p2DRender, CPoint pt, FLOAT fRadian, BOOL bCenter, DWORD dwBlendFactorAlhpa = 255, FLOAT fscalX = 1.0, FLOAT fscalY = 1.0 ) {
246     p2DRender->RenderTextureRotate( pt, this, dwBlendFactorAlhpa, fRadian, bCenter, fscalX, fscalY ); 
247 }
248 
249 void Render2( C2DRender* p2DRender, CPoint pt, D3DCOLOR color, float fscalX = 1.0f, float fscalY = 1.0f ) {
250     p2DRender->RenderTexture2( pt, this, fscalX, fscalY, color ); 
251 }
252 void RenderScal2( C2DRender* p2DRender, CPoint pt, DWORD dwBlendFactorAlhpa = 255, FLOAT fscalX = 1.0, FLOAT fscalY = 1.0, D3DCOLOR color = 0 ) {
253     p2DRender->RenderTextureColor( pt, this, fscalX, fscalY, color ); 
254 }

所以我真的很擅长C ++我知道一些基础知识和我试着学习,因为我通过这个预建项目的试验和错误,不是最好的学习方法,但它会教我足够的用我需要的东西。

根据我的理解,有两种不同的转换,编译器不知道要使用哪两种定义,对吧?

2 个答案:

答案 0 :(得分:0)

编译器在调用函数时说,参数列表为(C2DRender *, CPoint, float, int, float, float)。但是这个电话没有完全匹配。

有两位候选人,

void CTexture::RenderRotate(C2DRender *,CPoint,FLOAT,BOOL,DWORD,FLOAT,FLOAT)

和     void CTexture :: RenderRotate(C2DRender *,CPoint,FLOAT,DWORD,FLOAT,FLOAT)

你可以说,int可以转换为BOOLDWORD以匹配其中一个候选者,但编译器认为两者同样好。所以它无法决定并要求您澄清。

答案 1 :(得分:0)

在这一行上查看您的代码:

Source\Source\_Interface\WndTaskBar.cpp(9682) : error C2666: 'CTexture::RenderRotate' : 2 overloads have similar conversions

仔细查看参数的类型。编译器表示他们评估为

C2DRender *, CPoint, float, int, float, float

你有两个非常相似的功能指纹,它们都不是精确匹配,但是它们都可以通过一些转换来获取你提供的参数。

由于参数计数不同,我怀疑你已经体验了为什么不使用默认参数的第一课。

C2DRender *,CPoint,FLOAT,BOOL,DWORD,FLOAT,FLOAT
C2DRender *,CPoint,FLOAT,     DWORD,FLOAT,FLOAT

编译器可以将“int”转换为BOOL和DWORD,如果一个或两个函数中的浮点数都有默认值,它可以充实其余部分。

您可以通过准确指定要调用的内容来修复它:

RenderRotate(renderer, point, float1, (BOOL)theBoolValue, (DWORD)theDwordValue, float2, float3);