// ========================================================================== // $Id: decltype_ref.cpp,v 1.3 2016/09/19 18:11:25 jlang Exp $ // CSI2372 example Code for lecture 3 // ========================================================================== // (C)opyright: // // Jochen Lang // EECS, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.eecs.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@eecs.uottawa.ca // ========================================================================== // $Log: decltype_ref.cpp,v $ // Revision 1.3 2016/09/19 18:11:25 jlang // Aligned auto and decltype examples // // Revision 1.2 2016/09/19 17:38:22 jlang // decltype references cleaned up // // Revision 1.1 2014/09/13 20:00:11 jlang // fixed file name // // Revision 1.1 2014/09/13 19:48:03 jlang // Added C++11 features to lecture 3 // // // ========================================================================== #include using std::cout; using std::endl; int main( ) { int i=3, &iRef = i, *iPtr = &i; cout << "i = " << i << "\t"; cout << "iRef = " << iRef << "\t"; cout << "*iPtr = " << *iPtr << endl; decltype(i) iVal; // iVal is just an interger, // no need to initialize cout << "iVal = " << iVal << " (uninitilized int) "; cout << " and " << "i = " << i << endl; decltype(iRef) jRef = i; ++i; cout << "i = " << i << " and "; cout << "jRef = " << jRef << " (reference)" << endl; decltype(iPtr) kPtr; kPtr = iPtr; cout << "kPtr = " << kPtr << " (pointer)" << endl; decltype((i)) kRef = i; ++i; cout << "i = " << i << " and "; cout << "kRef = " << jRef << " (reference)" << endl; decltype(*iPtr) lRef = i; // *iPtr is an expression that can appear on the lhs of an assignment ++i; cout << "i = " << i << " and "; cout << "lRef = " << lRef << " (reference)" << endl; int *k = &lRef; return 0; }