User-Defined Data-Type or access Modifiers

  access-modifiers, c++, length-modifiers, modifier, oop

so the idea is to create a modifier like "long" or "unsigned" or "public" or "private" with user-defined behavior. Not for any real programming reason, just out of interest.

Perhaps I want a "beeg" modifier that squares the memory allocated (like a long, but on a different scale). I would then be able to do beeg int x = 0; without having to write a whole BeegInt class as well as BeegBool, BeegFloat, BeegDouble, etc. For bonus points, because it’s a user-created modifier, beeg could also make chars unsigned by default, but not so for ints (this one’s not as transparent, so likely not practical outside of code obfuscation)

One more example with access modifiers in case you guys aren’t convinced that this is useful yet: what if we had a display modifier that could create a variable that was public, but acted as a const outside of the scope in which it was declared. This isn’t worse than a getter (or so I don’t believe, please tell me if it is, although that’s not the point of this question), because it means we can write smaller, more digestible code with fewer functions (some of which will be unused by some clients anyways) while still not violating the principle of least privilege.

And so really what I’m asking is: "is any of this possible?" can I create my own user-defined modifiers like "long" or "public" but with a twist, if I really wanted to? Or is there no way to do this? Thanks for your time in reading this question and I hope it interests you!

Source: Windows Questions C++

LEAVE A COMMENT