//explicit keyword is used only with constructor
// which avoids conversion only it will allow to create objects
#include<iostream.h>
class sample
{
private:
int i;
public:
sample(){}
// explicit sample(int ii)
sample(int ii)
{
i=ii;
}
sample operator+(sample s)
{
sample temp;
temp.i=i+s.i;
return temp ;
}
void display()
{
cout<<i<<endl;
}
};
int main()
{
sample s1(25), s2;
s1.display();
s2=s1+25;
s2.display();
return 0;
}
//How to use explicit keyword in C++ with exaple
//How to use explicit keyword in C++ with exaple
//How to use explicit keyword in C++ with exaple
//Why to use explicit keyword in C++ with exaple
//Why to use explicit keyword in C++ with exaple
//overloading S2=S1+25;
// which avoids conversion only it will allow to create objects
#include<iostream.h>
class sample
{
private:
int i;
public:
sample(){}
// explicit sample(int ii)
sample(int ii)
{
i=ii;
}
sample operator+(sample s)
{
sample temp;
temp.i=i+s.i;
return temp ;
}
void display()
{
cout<<i<<endl;
}
};
int main()
{
sample s1(25), s2;
s1.display();
s2=s1+25;
s2.display();
return 0;
}
//How to use explicit keyword in C++ with exaple
//How to use explicit keyword in C++ with exaple
//How to use explicit keyword in C++ with exaple
//Why to use explicit keyword in C++ with exaple
//Why to use explicit keyword in C++ with exaple
//overloading S2=S1+25;
This information about Why to use explicit keyword in C++ is extremely useful for me! appreciation for giving out. it’s all very new and clearly written!
ReplyDeleteuk dissertation