Skip to content

Instantly share code, notes, and snippets.

@jacquelinekay
Created July 6, 2016 15:51
Show Gist options
  • Save jacquelinekay/4ad0db51923f67e24782ddf849972ca8 to your computer and use it in GitHub Desktop.
Save jacquelinekay/4ad0db51923f67e24782ddf849972ca8 to your computer and use it in GitHub Desktop.
#include <iostream>
class A {
public:
A(const char * foo) {
std::cout << "Invoking constructor" << std::endl;
s = std::string(foo);
}
A(const A& a) {
std::cout << "Invoking copy constructor" << std::endl;
s = a.s;
}
A(A&& a) {
std::cout << "Invoking move constructor" << std::endl;
s = a.s;
}
std::string s;
};
static A construct(const char * foo) {
A a(foo);
return a;
}
int main() {
A && a = construct("hello world");
std::cout << "Value of a: " << a.s << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment