문제

This is a cppcheck warning message.
Variable 'BUFFER_INFO' hides typedef with same name

The BUFFER_INFO is defined as following.

typedef struct tagBufferInfo
{
    CRITICAL_SECTION cs;
    Buffer* pBuffer1;
    Buffer* pBuffer2;
    Buffer* pLoggingBuffer;
    Buffer* pSendingBuffer;
}BUFFER_INFO, *PBUFFER_INFO;

And I wrote,

PBUFFER_INFO p = new BUFFER_INFO; // causes the warning.

What is the problem? How do I solve it?
Thanks.

도움이 되었습니까?

해결책

This looks like it might be a cppcheck bug.

However... what you have written is bad C++ style, prefer:

struct BUFFER_INFO
{
    CRITICAL_SECTION cs;
    Buffer* pBuffer1;
    Buffer* pBuffer2;
    Buffer* pLoggingBuffer;
    Buffer* pSendingBuffer;
};

I would also obsrve that it is not good C++ style to use all uppercase for type names (these are normally reserved for constants) and that typedefs that hide the fact that something is a pointer are normally not a good idea.

다른 팁

In C++ you can direcly use the Struct name without keyword struct and so you dont need the first typedef that is BUFFER_INFO. But for pointer you can still have it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top