macro and member function conflict
The workaround is to use the parenthesis: int max = (std::numeric_limits<int>::max)();
It allows you to include the windef.h
, doesn't require you to #undef max
(which may have adverse side effects) and there is no need to #define NOMINMAX
. Works like a charm!
How to properly solve macro conflict (GetMessage) between Windows API and DirectX API & other APIs developed by microsoft
nothing need do here and no any conflict or problems in your code. you already viewed this yourself
it compiled successfully and these methods can still be called
normally runtime
and you correct - methods called not by name but by address in virtual table. the winuser.h always included before IDXGIInfoQueue declaration, so already inside interface declaration GetMessage
expanded to GetMessageW
or GetMessageA
. the same in your code, which call method on interface ( DXGIInfoQueue->GetMessage
). as result names coincide.
But still, it just feels wrong using the wrong names...
here you have wrong feels. again - all is ok and nothing need todo
How to define a macro using other macros, when those other macros raise name conflicts
Compiling comments to make an answer:
Solution A,
if you for some reason have to stick with "ROW" and "COL" in your code (credits to melpomene):
enum { ROW = 100 };
enum { COL = 200 };
enum { ARRSIZE = ROW*COL };
Solution B,
if you are free to choose identifiers; more robust for future reuse:
Avoid the naming conflict by choosing different, non-conflicting, longer identfiers.
I have a superstitious distrust of short, obvious identifiers, the conflict you encountered is a good example why. Other examples have cost my employers quite some time and money.
(I have seen melpomene elsewhere not being interested in the reputation for an answer anymore, very altruistical. I think it is worth making a nice Q/A pair here and does not take anything from melpomene.)
VS2017 #error: : Macro definition of snprintf conflicts with Standard Library function declaration
As the error in your question shows, you have a macro definition for snprintf
that is no longer compatible with your current version.
So you need to look for the following:
#define snprintf _snprintf
You can either remove it or if you need to also compile your code with Visual Studio 2010 you can add the following condition:
#if _MSC_VER < 1700
#define snprintf _snprintf
#endif
how to avoid name conflicts coming from #define in C? (or C++)
You cannot work around this because that's the preprocessor goal: modifying your code on the fly. The solution is to adopt good coding practices: don't use the preprocessor for general programming. Also, use a naming discipline with namespaces. K what ? Name it CONVERSION_ID_K, CONVERSION_ID_L, and so on. Use lower case for variables, etc.
Related Topics
After Sending a Lot, My Send() Call Causes My Program to Stall Completely. How Is This Possible
How to Use Pre-Compiled Headers in Vc++ Without Requiring Stdafx.H
Observer Design Pattern in C++
Rotating a 2D Pixel Array by 90 Degrees
Why Is My Class Non Default-Constructible
Create Objects in Conditional C++ Statements
How Visitor Pattern Avoid Downcasting
Unaligned Access Through Reinterpret_Cast
Good C++ Array Class for Dealing with Large Arrays of Data in a Fast and Memory Efficient Way
C++ Get String from Clipboard on Linux
Use Static_Assert to Check Types Passed to MACro
How to Debug C++11 Code with Unique_Ptr in Ddd (Or Gdb)
Does Class/Function Order Matter in C++
Specializing Single Method in a Big Template Class
Why Is Operator""S Hidden in a Namespace
Given a Start and End Point, and a Distance, Calculate a Point Along a Line