Вопрос

I have many header files and source codes for my project in C++. I wanted to suppress warnings, therefore, came to know about #pragma warning preprocessor. I am able to suppress one kind of warning, namely 4251, by putting #pragma warning(push) #pragma warning(disable:4251) ...some declarations/prototypes #pragma warning(pop)

in the header file (utils.h) of the corresponding source file(utils.cpp), where this warning have been shown.

Now, there is another kind of warning (4146), which is occurring in my source file, clah.cpp. I am putting the same code, as mentioned, to the header file of this file (clahe.h). However, the compiler is not able to suppress this warning ? Can you please tell me if I am doing somewhere a mistake ? or, I am putting the pragma statements wrongly ? Thanks.

P.S., I am a beginner in C++.

Это было полезно?

Решение

If you have a header that has a

#pragma warning(push) 

on top and a

#pragma warning(pop) 

at the bottom, then after the header is parsed, the warning settings are reset. You'll need to put a pragma in your cpp file as well.

#include "someheader.h"

//this is the implementation file
//some code

translates, basically, to:

//contents of the header file
#pragma warning(push) 
#pragma warning(disable:4251)

//warning is disabled here

#pragma warning(pop)

//popped - initial state (warning enabled) back

//this is the implementation file
//some code
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top