質問

As the title say, when i try to compile my program I receive a debug error which says:

Error 7 error C2446: '>=' : no conversion from 'DWORD' to 'const char *'

Some code:

virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi) 
{ 
    return new CTextureAnimationCWDecorator(
               fFrameTime,n,(BYTE*)((unsigned char*)pi+((BYTE*)pIdx-(BYTE*)pfi))); 
}
virtual void __Excute(const CDecoratorData & d)
{
    fLastFrameTime -= d.fElapsedTime;
    while (fLastFrameTime<0.0f)
    {
         fLastFrameTime += fFrameTime;
          if (++(*pIdx) >= n) // error line
              *pIdx = 0;
    }
}
DWORD n;
float fLastFrameTime;
float fFrameTime;
BYTE* pIdx;
};

How can I solve this?

役に立ちましたか?

解決

There is a simple solution you have to cast the BYTE type to DWORD or the opposite like:

if (++(*pIdx) >= (BYTE)n) // error corrected

But this does lead me to question what you are doing. A DWORD is a much bigger storage that the BYTE type the pointer addresses - this comparison therefore looks dangerously like a spot where a subtle overflow bug might occur when n > 255.

Also you ruse of the ++ operator seems confusing - are you clear that this operator is NOT incrementing the pointer onto the next byte, but rather incrementing the value of the byte currently pointed to?

他のヒント

In MS environment, a DWORD is a 32-bit unsigned integer and BYTE is unsigned char.

 if (++(*pIdx) >= n) // error line

pdx makes BYTE, as pdx is BYTE you preincrement that, result is a BYTE now you compare with n, which is DWORD The resultant expression will be DWORD, as DWORD is wider than BYTE, but should work. What's the problem?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top