30 Sep 19:43
const references and synonyms
edA-qa <edA-qa <at> disemia.com>
2004-09-30 17:43:57 GMT
2004-09-30 17:43:57 GMT
This is a recall of a previous constant discussion. I would like to
differentiate between const instances and const references.
//the following is a shared reference to a const heap instance
T const ^ ref;
//the following is a const shared reference to a heap instance
T ^ const ref;
//const references disallow rebinding, ro conversion to non-const
//references
ref @= otherRef; //error, cannot rebind
void func( T^ param );
func( ref ); //error, cannot conver to non-const reference
This then needs to be extended to synonyms in the function call syntax.
To show why, here is an example of what bad happens without:
template<typename T>
void beNice( T& ref ) {
ref @= somethingElse;
}
The callers of this function have no guarantee that their shared
references aren't being rebound -- while sometimes they may want this,
other times clearly not. So:
template<typename T>
void beNice( T const& ) {
(Continue reading)
RSS Feed