Bitwise operations in class inheriting int

前端 未结 2 1120
时光取名叫无心
时光取名叫无心 2021-01-20 05:55

I\'ve inherited from int, because I wanted to implement a simple interface for bitwise operations. Due to the non mutability of int, I have to use the integer member functio

2条回答
  •  醉梦人生
    2021-01-20 06:18

    ints aren't subscriptable as well as being immutable, so you can't write a working __setindex__() method. It seems like what describing is basically a mutable bit-vector class, such as this one which appears to have been written by Guido. You can use the provided __int__() and __long__() methods to convert it an integer value (although I don't believe you need the latter any more).

提交回复
热议问题