문제

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