why we don't make pointer of child/derived class which points to base class ?

why we don't make pointer of child/derived class which points/assigns to base class object?
for example:

1
2
3
4
parent a; // a is a parent class object!
child * p = & a; // p is child class pointer !



why we do not do this in c++ ?
Last edited on
Parent is not a child. It does not have the interface of a child.

A question for you. What will "s" contain:
1
2
3
T a;
T * p = &a;
T * s = p+1;
if we print value of p it will print 00cofefc on console
if we print value of s it will print 00coff00 on console !
Yes, but what does that mean? Btw, what was the T in your test?
Last edited on
I am not very much familiar with hex numbers so i am not sure what that does mean !
you may explain this to me !

T is a class name/user defined data type (parent class) !
Repeat with these then:
1
2
3
4
5
6
7
class A {
  int a;
};

class B : public A {
  int b;
}

Topic archived. No new replies allowed.