Created
November 18, 2018 20:22
-
-
Save melvyniandrag/dc9dc620f50573489d8350416d33fef0 to your computer and use it in GitHub Desktop.
Looking at reference parameters to functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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