c++ constant function declaration variants?

后端 未结 3 1570
灰色年华
灰色年华 2021-01-21 21:22

Are all of the below declarations the same? If so, what is the standard way to declare a constant function?

const SparseMatrix transpose();

SparseMatrix transpo         


        
3条回答
  •  迷失自我
    2021-01-21 21:56

    The first one will return a SparseMatrix that is const and cant be changed.

    The second one declares a function that returns a SparseMatrix and assures the function will not change any class variables (assuming it is a member function, otherwise it wouldnt make sense with this deceleration) except for mutable members.

    The final one does both.

提交回复
热议问题