Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Solving a C4183 Conundrum

4.67/5 (2 votes)
11 Nov 2016CPOL1 min read 10.8K  
This tip describes how I resolved a C4183 compiler error emitted by the Visual C++ 2013 compiler.

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.

C++
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.

C++
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.

C++
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)