Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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.

 

 

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