Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Created October 28, 2014 21:27
Show Gist options
  • Save cengiz-io/5b918ccdd1b8ef80dacd to your computer and use it in GitHub Desktop.
Save cengiz-io/5b918ccdd1b8ef80dacd to your computer and use it in GitHub Desktop.
copy initialization and direct initialization
#include <iostream>
using namespace std;
class A {
public:
A() {
cout << "default constructor" << endl;
}
A(const A& x) {
cout << "copy constructor" << endl;
}
const A& operator = (const A& x) {
cout << "operator =" << endl;
return *this;
}
};
int main() {
A a; // default constructor
A b(a); // copy constructor
A c = a; // copy constructor
c = b; // operator =
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment