What's wrong with const?

前端 未结 12 2063
無奈伤痛
無奈伤痛 2021-01-31 12:06

What are the known shortfalls of const in C++ and C++0x?

12条回答
  •  花落未央
    2021-01-31 12:51

    The two main issues that I have seen frequent complaints about in newsgroups, are

    • The need to waste a lot of time on supporting non-const-aware APIs (especially Microsoft's).

    • The need to define both const and non-const version of a method.

    I think the latter could/should be supported by the language.

    Possibly in conjunction with support for covariant member function implementations, because both need some way to pick up the type of the this pointer.

    A third issue is that

    • const does not propagate to owned objects.

    Cheers & hth.,

提交回复
热议问题