0

I have a simple class Employee that has three strings (first, middle and last names) and defines copy and move constructors and assignment operators and prints a text when each one is called. I also have this code in my main class

int main() {
    Employee e = getEmp();

    return 0;
}

Employee getEmp() {
    Employee emp("John","","Smith");
    return emp;
}

And here's the output:

This is Employee constructor
This is Employee destructor

So the copy or move constructors are never called and only one Employee is created, whereas I was expecting a call to the move constructor when getEmp() returns. What is happening?

user798275
  • 441
  • 6
  • 14

0 Answers0