Skip to content

Instantly share code, notes, and snippets.

@jacquelinekay
Last active July 6, 2016 15:52
Show Gist options
  • Save jacquelinekay/b6098b211beaf7d1cc53b2f0f12f70b7 to your computer and use it in GitHub Desktop.
Save jacquelinekay/b6098b211beaf7d1cc53b2f0f12f70b7 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