views:

65

answers:

2

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.

+1  A: 

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.

Raghuram
+3  A: 

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.

anon