S
sks
dear all,
i have a problem . consider the following code
class ABC
{
int & r;
public: ABC( int &a) : r(a) {}
};
int main()
{
int d=10;
ABC Myobj(d)
}
i cannot understand how this works and Have two question in my mind
1) we cannot have reference to reference . but here we have a as
refrerence to d and r is reference to a . how is this possible ?
2) It is generally known that object is created and then constructor is
called . and references have to be initialised immediately . so my
question since My Obj is created then Constructor is called that means
the object is created in the memory and still the reference is not
initialised . How is this possible ?
i have a problem . consider the following code
class ABC
{
int & r;
public: ABC( int &a) : r(a) {}
};
int main()
{
int d=10;
ABC Myobj(d)
}
i cannot understand how this works and Have two question in my mind
1) we cannot have reference to reference . but here we have a as
refrerence to d and r is reference to a . how is this possible ?
2) It is generally known that object is created and then constructor is
called . and references have to be initialised immediately . so my
question since My Obj is created then Constructor is called that means
the object is created in the memory and still the reference is not
initialised . How is this possible ?