1. 程式人生 > 其它 >VS2019使用NTL庫時出現大量tools.h報錯解決辦法

VS2019使用NTL庫時出現大量tools.h報錯解決辦法

寫作業遇到的。
大致的情況如圖:

問題出在tools.h 標頭檔案中的 NTL_NO_MIN_MAX.
在NTL官網找到的具體說明如下:

好像有點糊。文字內容也貼在這裡:

TIP: When writing windows applications using NTL (as opposed to console applications) you might want to compile your program with the NTL_NO_MIN_MAX macro defined. This suppresses the declaration of several min and max functions in file tools.h that conflict with macro names in the MFC header files. Do not attempt to build the library with this macro defined -- only programs that use the library. Another solution is to define the macro NOMINMAX, which will tell the Microsoft compiler to not define min/max macros.

解決辦法:
在引入Windows.h前加上NOMINMAX的巨集定義。

#define NOMINMAX
#include<Windows.h>

題外話(最終的解決辦法):
因為另外幾個專案的標頭檔案也都基本相同,但是隻有這裡遇到了這種情況所以覺得很神奇。研究了一下,發現只要在引入Windows.h前引入NTL庫就不會有報錯出現,所以我這裡是一個頭檔案裡有include ntl,另一個裡面有include Windows.h,在引入時把它們兩個調換一下順序就可以了。
應該就是上面圖裡說的,如果先在windows.h裡面定義了min和max就會產生衝突?