www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



digitalmars.D - Re: rtti cast

↑ ↓ ← terranium <spam here.lot> writes:
BCS Wrote:

 The point is that offtent a failed cast is not an indecation of an 
 error. For instance code like this
 
 class A {}
 class B1 : A {}
 class B2 : A {}
 
 void foo(A a)
 {
    if(auto b = cast(B1)a) {}
    else if(auto b = cast(B2)a) {}
    else {}
 }

I see polimorphism should help here.
May 08 2008
↑ ↓ → BCS <ao pathlink.com> writes:
Reply to terranium,

 BCS Wrote:
 
 The point is that offtent a failed cast is not an indecation of an
 error. For instance code like this
 
 class A {}
 class B1 : A {}
 class B2 : A {}
 void foo(A a)
 {
 if(auto b = cast(B1)a) {}
 else if(auto b = cast(B2)a) {}
 else {}
 }


dosn't always work module third.party.lib; class A {} module my.lib.one class B1 : A { int newFn(){...}} module my.lib.teo class B2 : A { char somthingNew(char[] c){...}} void foo(A a) { if(auto b = cast(B1)a) b.newFn(); else if(auto b = cast(B2)a) b.somthingNew("hello"); else throw new Error("a isn't a B1 or B2"); }
May 08 2008