Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Jan 26, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Operator dynamic_cast<> is Aware of Access Specifications

Operator dynamic_cast<> fails when it cannot convert its argument to the desired type. Usually, such a failure results from an attempt to cast an object to a non-related class. But there can be another reason for it--an attempt to cast a derived object to its base class will fail in case of private inheritance:
class Container {/*..*/ };
class Allocator{/*..*/};
class Stack: public Container, private Allocator  {/*..*/ }; 

void main()
  Stack s;
 Allocator* p = dynamic_cast<Allocator*> (&s); // runtime failure; Allocator is an inaccessible base
In this example, dynamic_cast fails because Stack is not publicly derived from Allocator.
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date