0

I have a class that is exported and it uses a header only structure as a member variable.

#include "SomeStruct.h"

class API_CLASS SomeClass
{
public:
// ...
private:
#pragma warning( push )
#pragma warning( disable: 4251 )
    SomeStruct _active;
#pragma warning( pop )
};

I get warning 4251 as the structure is not exported. The structure is part of an external code and not a part of current scope.

I would like to make this code a bit more readable as this is a header I will distribute. Ideally, I want the class to read

#include "SomeStruct.h"

class API_CLASS SomeClass
{
public:
// ...
private:
DISABLE_WARNING_BEGIN(4251)
    SomeStruct _active;
DISABLE_WARNING_END
};

It may be more work to disable multiple warnings but if that can be done, then great but not necessary. The macro should result in code only for WIN32 environment. I have tried to write the macro but to include a '#' is beyond me.

Ram
  • 3,045
  • 3
  • 27
  • 42
  • 2
    To be honest I wouldn't go there... The warning numbers are compiler-specific anyway, so you'd be obscuring rather than clarifying. For ignoring a warning for the following line only, you can use the more compact "#pragma warning(suppress: 4251)". – heinrichj Mar 19 '14 at 06:55

2 Answers2

0

I can live with this. This is better than what I have now.

#include "SomeStruct.h"

class API_CLASS SomeClass
{
public:
// ...
private:
#pragma warning(suppress: 4251)
    SomeStruct _active;
};

Thanks to Heinirichj

Ram
  • 3,045
  • 3
  • 27
  • 42
0

To add #pragma into a MACRO, you may use:

  • __pragma with MSVC
  • _Pragma with gcc

See Pragma in define macro for more detail.

Community
  • 1
  • 1
Jarod42
  • 203,559
  • 14
  • 181
  • 302