C++ 17 and byte

Post Reply
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

C++ 17 and byte

Post by IXix »

C++ 17 implements std::byte so if I do "using namespace std" it clashes with the byte typedef in MachineInterface.h and I get all kinds of compiler errors.

Is there any way to fix this that doesn't involve me prefixing every one of the bazillion strings/vectors/maps/sets and god knows what else in my project with "std::"? :shock:
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: C++ 17 and byte

Post by oskari »

You can comment out 'typedef unsigned char byte' in MachineInterface.h, #include <cstddef> and change references to byte to std::byte in the file.

Or if you don't want to modify the file you can do

Code: Select all

namespace Buzz
{
    #include "MachineInteface.h"
}
and use Buzz::CMachineInterface etc.
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: C++ 17 and byte

Post by IXix »

oskari wrote: Mon Nov 09, 2020 7:39 am You can comment out 'typedef unsigned char byte' in MachineInterface.h, #include <cstddef> and change references to byte to std::byte in the file.

Or if you don't want to modify the file you can do

Code: Select all

namespace Buzz
{
    #include "MachineInteface.h"
}
and use Buzz::CMachineInterface etc.
Thanks Oskari. One question though, std::byte is an enum class (which is still a new thing for me :lol:) so is that compatible with the simple unsigned char byte that we know and love?
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: C++ 17 and byte

Post by IXix »

IXix wrote: Mon Nov 09, 2020 9:38 amis that compatible with the simple unsigned char byte that we know and love?
Duh, brain fail. :roll: :lol:
Post Reply