Skip to content

Instantly share code, notes, and snippets.

@melvyniandrag
Created November 18, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvyniandrag/dc9dc620f50573489d8350416d33fef0 to your computer and use it in GitHub Desktop.
Save melvyniandrag/dc9dc620f50573489d8350416d33fef0 to your computer and use it in GitHub Desktop.
Looking at reference parameters to functions
/**
* In this file we look at a couple of functions that accept an integer literal
* and one that won't.
*
* g++ -std=c++11 refs.cpp -o refs
*/
#include <iostream>
void f( const int& i ){
std::cout << "constant lvalue reference can be assigned a value" << std::endl;
}
void g( int&& i ){
std::cout << "rvalue reference can be assigned a value" << std::endl;
}
void h( int& i ){
std::cout << "non-const lvalue reference cannot be assigned a value." << std::endl;
}
int main(){
f(1);
g(1);
//h(1); //if you uncomment this, you get a compiler error.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment