Is there a way to disable implicit casts from UInt32 to char?

后端 未结 4 1723
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 03:03

I am working on code that takes as input a ton of ascii text defined by specific protocol. The original author interpreted \"string(1)\" datatypes in the original protocol

4条回答
  •  轮回少年
    2021-01-18 03:48

    You should be able to write a trivial replacement class for char (which holds a char as its data, and provides a few cast operators to allow it to be used as if it were a char) that doesn't allow implicit casts to/from ints, and then do a search and replace of 'char' with the 'mychar'. This will throw up compiler errors that you can fix, and then if you wish you can revert the code to using char again, or stick with your class.

    This is a good example of a place where temporary use of macros is so useful in c++...

提交回复
热议问题