Re: [GD-General] Re: Simulating constrained genericity in C++
Brought to you by:
vexxed72
From: Joe <dar...@ya...> - 2001-12-27 19:39:54
|
So assuming point2d was an interface too, wouldn't you just do interface point3d extends point2d{ public float z(); } and then your old implimentation should work > >Sure, here is the initiale code in Java (or something fairly close, I'll >probably get the syntax wrong): > >interface point3d { > public float x(); > public float y(); > public float z(); >} > >class point3d_impl implements point3d { ... } > >Now somebody has written some code that only works on 2d points, like so: > > public int dist(point2d p1, point2d p2) > >where point2d has the expected interface definition. Can we pass objects >of type point3_impl to this method? If inheritence defines subtyping >(with the implements keyword being a form of inheritence) then one >cannot. If names and their types define the subtyping relationship then >this is perfectly legal. > >This isn't the best motivating example, but it should be easy enough to >understand the principle. > >Patrick > > >_______________________________________________ >Gamedevlists-general mailing list >Gam...@li... >https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > |