"bcc32c Error : reference to 'byte' is ambiguous"
This error is often seen relating to a Gdiplus
header, when headers that contain using namespace std;
are include before the Gdiplus
header.
The reason for the error is as follows:
1) windows.h
defines byte
2) stddef.h
defines std::byte
This is key: If after this point the compiler sees using namespace;
, byte
become ambiguous because it refers to both ::byte
(from "windows.h") and std::byte
(from "stddef.h").
3) Now when gdiplus.h
is seen, since it does not qualify byte
, the reference is ambiguous.
And you will see this error:
bcc32c Error GdiplusPath.h(146): reference to 'byte' is ambiguous
rpcndr.h(197): candidate found by name lookup is 'byte'
stddef.h(258): candidate found by name lookup is 'std::byte'
It is generally not recommended to have using namespace;
in headers.
If the code requires this, then you must make sure that the gdiplus headers are included before the headers that contains using namespace;
.
OR
If that is not possible do something like this:
#include <windows.h>
#include <stddef.h>
using namespace std;
#define byte ::byte //<<<<<remove these lines to see the error
#include <Gdiplus.h>
#undef byte //<<<<<remove these lines to see the error
#include <stdio.h>
int main()
{
std::byte test{ 2 };
printf("%X \n",test);
return 0;
}