Const-correctness and immutable allocated objects

前端 未结 3 1780
难免孤独
难免孤独 2021-01-18 10:05

During a recent discussion (see comments to this answer), R.. recommended to never create aliases for pointer-to-const types as you won\'t be able to deallocat

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 10:40

    If the object is truly immutable, why give the user the pointer to it and risk an opportunity of corrupt object? Keep the object address in the table, return an opaque handle (an integer table index?) to the user and accept that handle in your library routines.

提交回复
热议问题