且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以下是使用const_cast未定义的行为?

更新时间:2023-11-10 20:14:22

C ++标准,第5.2.11节/第7节[const cast]

C++ standard, section § 5.2.11/7 [const cast]


[注意:根据对象的类型,通过指向const_cast的指针,值或指针到数据成员写操作限定符可能会产生未定义的行为。 -end note]

[ Note: Depending on the type of the object, a write operation through the pointer, lvalue or pointer to data member resulting from a const_cast that casts away a const-qualifier may produce undefined behavior. —end note ]

GetA() code> Bob ,因此此程式不涉及未定义的行为。

GetA() does not write any member of Bob, so this program does not involve undefined behavior.