Introduction
In the course of implementing a class in a Visual C++ project, I encountered an error (documented as a warning) that I couldn't resolve by any of the methods discussed elsewhere. Thankfully, the solution that I developed, though slightly novel, is quite straightforward; move the typedef directly into the class definition header.
Background
Having worked more in straight C than C++, and implemented C interfaces for most of my custom APIs, I was accustomed to declaring a structure and a pointer to one of its kind as follows.
typedef struct _PVT_SAFER_MUTEX
{
HANDLE ThisMutex ;
DWORD OwnerThread ;
} PVT_SAFER_MUTEX , * LPPVT_SAFER_MUTEX ;
It was a matter of habit to define structures and pointers to structures in this way in a header, include that header within another header, then declare functions that return the pointer type.
LPPVT_SAFER_MUTEX MyFunction ( SAFEER_MUTEX_HANDLE pHandle ) ;
This works like a champ in straight C code.
Now comes a need to do something similar in the header that declares a class.
LPPVT_SAFER_MUTEX CHandleManager::GetMutexInfo ( SAFEER_MUTEX_HANDLE pHandle ) ;
Try this with the structure typedef in a separate header, and you get Compiler Warning (level 1) C4183, 'identifier': missing return type; assumed to be a member function returning 'int'.
Points of Interest
After about an hour of studying numerous articles about compiler warnning/error C4183, I decided to move the typedef from the external header into the header that declares the C++ class that contains methods that return pointers to the structure.
This worked.
On reflection, putting the typedef in the header that defines the class that uses it is a cleaner design, because it makes the class declaration more self-contained.
History
Friday, 11 November 2016 is the initial publication of this tip.