Created
April 22, 2022 04:00
-
-
Save ratmcu/f7097475f0c61b4e4df38de57951040a to your computer and use it in GitHub Desktop.
example that shows off a function that can accept a lvalue reference as well as a rvalue
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
#include <iostream> | |
template<typename T> | |
void fnc(T&& x) | |
{ | |
// std::cout << x; | |
x++; | |
} | |
int main() | |
{ | |
fnc(10); // Nope! | |
// This works instead: | |
int x = 10; | |
fnc(x); | |
std::cout << x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment