Sphere: Related Content
/*
* In one of the interviews I had attended very recently, I had been asked to use
* reference variable as a class member. At that moment I was not able to answer.
* But later I found the answer and here it is
*/
#include <iostream>
using namespace std;
class RefVar
{
int i;
int &ra;
public:
//RefVar(a) : ra(i) { i = a;} // OK
RefVar(a) : ra(i), i(a) {}; // OK
/*
RefVar(a) {
i = a;
ra = i;
} */
// NOT OK
/*
RefVar(a) {
ra = i;
i = a;
} */
// NOT OK
//RefVar(a) { ra = a ;} // NOT OK
void getRefVar();
};
void RefVar :: getRefVar()
{
cout << "value of ra " << ra << endl;
}
int main()
{
int a = 7, b = 6;
RefVar r(a);
r.getRefVar();
int& p = a;
p = b;
cout << "value of p " << p << " value of a " << a << endl;
p = 9;
cout << "value of p " << p << " value of a " << a << endl;
return 0;
}
Gaetz Ethics Report Blocked, and the Trial That’s Horrified France
-
Plus, a $6.2 million piece of fruit.
23 minutes ago
No comments:
Post a Comment