Recently, I face an interview. The question faced by me is what is data overriding? I know how to override the function in C++.
class base {
public:
int x;
int y;
}
class der : public base
{
int x;
int y;
}
please do need full.
Join Stack Overflow to learn, share knowledge, and build your career.
Recently, I face an interview. The question faced by me is what is data overriding? I know how to override the function in C++.
class base {
public:
int x;
int y;
}
class der : public base
{
int x;
int y;
}
please do need full.
Data overriding?
There's no such thing.
The base class data are shadowed in der
but they are accessible in der
using the scope resolution operator ::
, e.g. base::x
.
When asked a question that's incorrectly posed in an interview, a strong candidate will point out the correct answer tactfully. For very senior hires I tend to ask a nonsense question deliberately to test the softer skills of the candidate.
base::x
name will be hidden byder::x
, but still accessible. – Evg Oct 22 '20 at 8:30der
has both it's ownint x
and theint x
of thebase
class encapsulated. – t.niese Oct 22 '20 at 8:31