Can a pointer to a base class can point to objects of a derived class?

Can a pointer to a base class can point to objects of a derived class?

Explanation: A base class pointer can point to a derived class object, but we can only access base class member or virtual functions using the base class pointer because object slicing happens when a derived class object is assigned to a base class object.

Which of the following is correct base class pointer object Cannot point to a derived class object?

3. Which of the following is correct? Explanation: C++ does not allow a derived class pointer to point a base class pointer whereas Base class can point to a derived class object. Both base class and derived class can have pointer objects.

Which of the following statement is correct a base class pointer Cannot point to derived class?

Answer:b. Derived class pointer cannot point to base class.

Can a base class pointer call methods in the derived class?

Is it possible for base class pointers to call methods declared in the derived class only? No, you can only call methods that are part of the class.

Why can’t a derived pointer reference a base object?

similarly a derived object is a base class object (as it’s a sub class), so it can be pointed to by a base class pointer. However, a base class object is not a derived class object so it can’t be assigned to a derived class pointer.

What is a pointer to derived class?

A pointer to derived class is a pointer of base class pointing to derived class, but it will hold its aspect. This pointer of base class will be able to temper functions and variables of its own class and can still point to derived class object.

What can hold the address of a pointer to the base class base class object derived class object?

Discussion Forum

Que. A pointer to the base class can hold address of
b. only derived class object
c. base class object as well as derived class object
d. None of the above
Answer: base class object as well as derived class object

What is base pointer and why it is being used?

The base pointer is conventionally used to mark the start of a function’s stack frame, or the area of the stack managed by that function. Local variables are stored below the base pointer and above the stack pointer.

What happens if the base and derived class contains definition of a function with same prototype?

What happens if the base and derived class contains definition of a function with same prototype? Compiler reports an error on compilation. Only base class function will get called irrespective of object. Only derived class function will get called irrespective of object.

Which of the following statement is correct base class pointer Cannot?

Base class pointer cannot point to derived class. Derived class pointer cannot point to base class.

Which of the following class Cannot be a base class?

If a class is enclosing more than one class, than it can be called as base class of those classes. Explanation: When a class have more than one nested classes, it is known as enclosing class. It can’t be called as parent or base class since there is no inheritance involved.

Why can’t a pointer to a derived class point to it?

The actual reason is – a derived class has all information about a base class and also some extra bit of information. Now a pointer to a derived class will require more space and that is not sufficient in base class. So the a pointer to a derived class cannot point to it.

How do you assign a base pointer to a derived pointer?

A derived pointer cannot be assigned a pointer to a base type without casting simply because it cannot tell if the base pointer is of the Derived type or one of its children. If assign an address from a base class pointer into a derived class pointer, you can potentially assign a base class object to a derived class pointer.

Can I assign a base class object to a derived class?

If assign an address from a base class pointer into a derived class pointer, you can potentially assign a base class object to a derived class pointer. You run the risk of accessing derived class members when you don’t have a derived class.

What is the use of base class pointer?

This pointer of base class will be able to temper functions and variables of its own class and can still point to derived class object.