Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I redefine a built-in type inside a namespace?

I would like to redefine the built-in type bool inside a library's namespaces and classes because they need to work differently but I would like to keep the name bool : ex::bool, ex::false, ex::true. But my compiler doesn't let me do that, I tried something like this :

namespace ex {
    typedef uint8_t bool;
    const uint8_t false = 0;
}

I also tried prefixing bool and false with ex:: inside the definition to emphasis the fact that it is in ex but it doesn't work. What could I do to have ex::bool ?

like image 789
linternetsansfil Avatar asked Dec 29 '25 04:12

linternetsansfil


1 Answers

What could I do to have ex::bool ?

You can't do anything. bool and false are hardwired with meaning by the language specification and are intrinsic keywords. You can't change their meaning any more than you can change the meaning of 0, if or while.

Choosing different names (such as Bool and False) is your only option.

like image 135
StoryTeller - Unslander Monica Avatar answered Dec 30 '25 19:12

StoryTeller - Unslander Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!