cnbatch / dynarray

A header-only library, VLA for C++ (≥C++14). Extended version of std::experimental::dynarray
BSD 3-Clause "New" or "Revised" License
14 stars 0 forks source link

does it work with win32 MFC projects in MSVC #1

Open rameshdk12 opened 10 months ago

rameshdk12 commented 10 months ago

Hi, Does it work with win32 MFC projects in MSVC 17?. I am using the neat version of dynarray.hpp

I am creating an array in global namespace as below. If I include stdafx.h it doesn't compile.

dynarray.hpp line 920 '(' illegal token on right side of :: is the first error.

//code begins

include "StdAfx.h"

include "dynarray.hpp"

vla::dynarray<int, 3> arr(1, 1, 1, 0);

//a dummy function void fun() {

}

//code ends

Thanks Ramesh D

cnbatch commented 10 months ago

This error is caused by the min/max macros of header conflict with C++ STL. Related topics:

Solution: The issue can be solved by adding NOMINMAX to ‘Preprocessor Definitions’: Click on ‘Project’ in the menu bar at the top of the Visual Studio window and select ‘Properties’. (or right click on your project in Visual Studio, select Properties) And then goto C/C++ → Preprocessor, add NOMINMAX to ‘Preprocessor Definitions’.

rameshdk12 commented 10 months ago

Thanks for your response The given solutions did not work for me. I put NOMINMAX in preprocessor definitions

it was confusing the max() of limits.h with the macro max

added the following two lines in the beginning of dynarray.h

``

undef max

undef min

and adding following to end of dynarray..h

ifndef max

define max(a,b) (((a) > (b)) ? (a) : (b))

endif

ifndef min

define min(a,b) (((a) < (b)) ? (a) : (b))

endif

``

Now it compiles without errors.