From: Andrew S. <ans...@se...> - 2002-01-25 14:43:44
|
On Friday 25 January 2002 06:23 am, Richard Bown wrote: > > > And why pass "const int &" to a function instead of "int"? > > > > No good reason. And "const Rosegarden::timeT&" either. Fixed. > > Obviously I was wrong. Explain. actually, i think there would be a very, very good reason for passing things around as references const or not - even integers. for me, looking Rosegarden::timeT, i don't know what that is. it could be a structure, it could be an integer, it could be a class - i don't care. i just know its a time value. so, since it could be either or, you should probably always pass it around with reference semants. i.e.: const Rosegarden::timeT &get_time(); void set_time( const Rosegarden::timeT &time ); now, if it is an integer, you can replace it with a class and don't have to change any of the interfaces that use it. > Why? Semantically they're the same (here's an integer, and you > can't change it). actually, that's not entirely true... int &ref = const_cast< int & >( get_const_integer_ref() ); now you a reference to a returned integer that you CAN change. of course, i don't know how many people would actually do that, but as an example, it goes a long way to show off the semantic differences. andy |