Вопрос

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