Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #9829
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: dynamic_cast and generic pointer |
| Date | 2011-09-06 16:48 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <j460vh$jro$1@dont-email.me> (permalink) |
| References | <3d7f54db-fcbe-4f00-92c4-8d63c38d8cab@glegroupsg2000goo.googlegroups.com> |
On 9/6/2011 3:38 PM, asit wrote:
> /*
> * File: main.cpp
> * Author: asit
> *
> * Created on 6 September, 2011, 7:08 PM
> */
>
> #include<cstdlib>
> #include<iostream>
>
> using namespace std;
>
> /*
> *
> */
>
> class A
> {
> public:
> virtual void show()
> {
> cout<<"A"<<endl;
> }
> };
> class B : public A
> {
> public:
> void show()
> {
> cout<<"B"<<endl;
> }
> };
> class C : public A
> {
> public:
> void show()
> {
> cout<<"C"<<endl;
> }
> };
>
> int main(int argc, char** argv)
> {
> B ob = new B;
^^^^^^^^^^^^^ Cannot happen in C++
> void *ptr;
> ptr = dynamic_cast<void*>(&ob);
> B* pt2 = dynamic_cast<B*>(ptr);
> return 0;
> }
>
>
>
> In the above code, why does the casting fails ??
Because it's not C++ code...
V
--
I do not respond to top-posted replies, please don't ask
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
dynamic_cast and generic pointer asit <lipun4u@gmail.com> - 2011-09-06 12:38 -0700
Re: dynamic_cast and generic pointer Victor Bazarov <v.bazarov@comcast.invalid> - 2011-09-06 16:48 -0400
Re: dynamic_cast and generic pointer asit <lipun4u@gmail.com> - 2011-09-06 14:23 -0700
Re: dynamic_cast and generic pointer Ian Collins <ian-news@hotmail.com> - 2011-09-07 10:09 +1200
Re: dynamic_cast and generic pointer "Default User" <defaultuserbr@yahoo.com> - 2011-09-06 18:07 -0500
Re: dynamic_cast and generic pointer Joe Greer <jgreer@doubletake.com> - 2011-09-08 14:45 +0000
Re: dynamic_cast and generic pointer Asger-P <junk@asger-p.dk> - 2011-09-07 01:08 +0200
Re: dynamic_cast and generic pointer Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-07 00:02 -0500
Re: dynamic_cast and generic pointer Juha Nieminen <nospam@thanks.invalid> - 2011-09-07 06:22 +0000
Re: dynamic_cast and generic pointer Goran <goran.pusic@gmail.com> - 2011-09-07 04:16 -0700
Re: dynamic_cast and generic pointer BGB <cr88192@hotmail.com> - 2011-09-08 23:17 -0700
csiph-web