Last active
December 20, 2015 02:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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