Global namespace scope operator for function definition

I am creating a C wrapper around a C ++ library. One of the common mistakes when doing this is to declare a function and define that for some reason does not match (typo, rename, argument, added / deleted, etc.).

For instance:

// enabledata.h MDS_C_API const char* motek_mds_enable_data_get_enable_command_name(); // enabledata.cpp const char* motek_mds_enable_data_enable_command_name() { ... } 

The names do not match, but due to the lack of features for these functions, it will not lead to any compilation errors and will be displayed much later on the line as a communication error.

I want the compiler to help me find these errors using the global visibility operator as follows:

 const char* ::motek_mds_enable_data_get_disable_command_name() { ... } 

Now it will display as a compilation error if the function has not yet been declared, which is exactly what I want.

However, this does not work when the function returns typedef:

 int32_t ::motek_mds_enable_data_is_enabled(const Data* a_Data) { ... } 

This will result in an attempt to use int32_t as the scope, which of course will result in an error:

 left of '::' must be a class/struct/union 

Are there any ways to make this work? Of course, better alternatives are also welcome.

I am currently using Visual Studio 2015 Update 2.

+6
source share
1 answer

You can always copy the declarator-id:

 int32_t (::motek_mds_enable_data_is_enabled)(const Data* a_Data) { ... } // ^ ^ 
+4
source

All Articles