Why is my return type meaningless?

后端 未结 6 726
别跟我提以往
别跟我提以往 2021-01-11 16:05

I am trying to use a return type of const MyClass * const. However, I get a warning:

Warning: #815-D: type qualifier on return type is m

6条回答
  •  粉色の甜心
    2021-01-11 16:30

    One simple way of making sure you're defining the return type you want is to always add modifiers on the right (as opposed to left) side of original type.

    MyClass                 // MyClass object
    MyClass const           // MyClass object which can't be modified
    MyClass const &         // reference of an unmodifiable MyClass object 
    MyClass const *         // pointer to an unmodifiable MyClass object
    MyClass const * const   // unmodifiable pointer to an unmodifiable MyClass object
    MyClass const * const & // reference of an unmodifiable pointer to an unmodifiable MyClass object
    

    That should help make sure your return types are never meaningless again :)

提交回复
热议问题