user: In C++, do class objects automatically get passed in as reference to other functions?

assistant: In C++, whether class objects are passed in as reference or by value depends on how the function is declared and called.

If a function is declared to take a class object by reference using the '&' operator in the parameter list, then the object will be passed in as a reference. For example:

void myFunction(MyClass& obj) {
  // Do something with obj
}
In this case, the 'obj' parameter is a reference to a MyClass object, so any changes made to 'obj' within the function will be reflected in the original object that was passed in.

However, if a function is declared to take a class object by value (without using the '&' operator), then a copy of the object will be made and passed to the function. For example:

void myFunction(MyClass obj) {
  // Do something with obj
}
In this case, 'obj' is a copy of the original object that was passed in, so any changes made to 'obj' within the function will not be reflected in the original object.

So in summary, whether a class object is passed in as a reference or by value in C++ depends on the function declaration and call.

user: You should talk a bitnabour Rvalue vs Lvalue and so on.

assistant: First, let's start with the basics. In C++, an Lvalue is an expression that refers to a memory location, while an Rvalue is an expression that represents a value stored at some memory location. Simple enough, right? But wait, there's more.

One of the main differences between Rvalues and Lvalues is that Rvalues can't be assigned a value, while Lvalues can. This is because an Lvalue is a memory location that can be modified, whereas an Rvalue is just a value that's stored in memory and can't be modified. It's like trying to change the value of a constant - it's not going to happen.

But here's where things get a little more complicated. In some cases, an Rvalue can be implicitly converted into an Lvalue. For example, if you have a function that takes an argument by reference, and you pass in an Rvalue, the compiler will implicitly create a temporary object and bind the reference to that object. This allows you to modify the temporary object, which in turn modifies the original Rvalue. Confusing, right?

And that's not even the half of it. There are also Rvalue references, which were introduced in C++11. An Rvalue reference is a reference that can only bind to an Rvalue. This allows you to move the contents of an Rvalue into a new object, rather than copying the contents. This is particularly useful for objects that are expensive to copy, such as large arrays or complex data structures.

But wait, there's still more. In some cases, an Rvalue reference can also bind to an Lvalue, but only if the Lvalue is about to be destroyed. This is known as an "expiring" reference, and it allows you to take advantage of move semantics even when dealing with Lvalues.

So, to sum up, Rvalues are expressions that represent values stored at memory locations, while Lvalues are expressions that refer to memory locations. Rvalues can't be assigned a value, while Lvalues can. However, in some cases, Rvalues can be implicitly converted into Lvalues, and Rvalue references can be used to move the contents of an Rvalue into a new object. And if that wasn't confusing enough, Rvalue references can also bind to Lvalues in certain circumstances.

So there you have it - an explanation of Rvalue versus Lvalue in C++. I hope this clears things up for you. Or maybe not. Who knows? It's C++, after all.