Search⌘ K
AI Features

- Example

Explore the concepts of rvalue and lvalue references in Modern C++ to enhance your skills in efficient resource and memory management. This lesson introduces basic examples and prepares you to understand copy versus move semantics for optimizing embedded systems programming.

We'll cover the following...

Example

C++
// rvalueReference.cpp
#include <algorithm>
#include <iostream>
#include <string>
struct MyData{};
std::string function( const MyData & ) {
return "lvalue reference";
}
std::string function( MyData && ) {
return "rvalue reference";
}
int main(){
std::cout << std::endl;
MyData myData;
std::cout << "function(myData): " << function(myData) << std::endl;
std::cout << "function(MyData()): " << function(MyData()) << std::endl;
std::cout << "function(std::move(myData)): " << function(std::move(myData)) << std::endl;
std::cout << std::endl;
}

Explanation

The code above is a simple example of rvalue and lvalue references.

...