Skip to content

Instantly share code, notes, and snippets.

@shaina7837
Last active December 20, 2015 02:59
Show Gist options
  • Save shaina7837/6060161 to your computer and use it in GitHub Desktop.
Save shaina7837/6060161 to your computer and use it in GitHub Desktop.
output: simple copy constructor copy assignment operator marks 82 name shaina marks 0 name
#include <iostream>
using namespace std;
class student
{
string name;
float marks;
public: //simple constructor with parameters
student (const string n, const float m){
name = n;
marks = m;
cout << "simple " <<endl;
}
//copy constructor definition
student (const student &st) {
cout<< "copy constructor" <<endl;}
//copy assignment operator definition
student& operator=(const student&){
cout << "copy assignment operator" <<endl;
}
void show(){
cout << "marks " << marks << endl;
cout << "name " << name <<endl;
}
};
main()
{
student s1("shaina",82);
student s2(s1);//copy constructor calling
s2 = s1;//copy assignment operator calling
s1.show();
s2.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment