#include<iostream>
using namespace std;
class alpha{
private:
int data;
public:
alpha(){}
alpha(int a){data=a;}
void display(){
cout<<data;
}
alpha operator =(alpha& a){
cout<<data;
data=a.data;
cout<<"\n assignement operator invoked";
return alpha(data); // is temporary object created is returned to a2 object ?//why it can't be returned by reference?what is the difference b/w assignement and initiallizing
}
};
int main(){
alpha a1(123);
alpha a2(10);
a2=a1;
cout<<"\na2";a2.display();
a1.display();
return 0;
}
saransh60 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.