i'm in process of changing game engine's language c++ c#. in c++, can inheret 2 classes in class makes things lot simpler, find impossible in c#. instead, must use interfaces.
i've looked around examples , know there lot here; can't figure out how implement in case.
please note followed tutorial generate code, , such knowledge on polymorphism might wrong.
the c++ code:
class tilemap : public sf::drawable, public sf::transformable { ... private: //this virtual function don't have window.draw(target, states), can window.draw(instance) //this called polymorphism? virtual void draw(sf::rendertarget& target, sf::renderstates states) const { // apply transform //this isn't our method, assume it's in draw() default. //or generates finished quads in 1 image instead of multiple ones. states.transform *= gettransform(); // apply tileset texture //this puts texture on we're going draw (which converted in single texture) states.texture = &m_tileset; // draw vertex array target.draw(m_vertices, states); } }
my tilemap class inherets drawable
class. states.transform *= gettransform()
means need inheret transformable
class.
however, can't in c# c++, inheriting both classes doesn't work. where, think, need use interfaces.
public interface transformable{ } public interface drawable : transformable{ }
i guess in drawable class implement virtual draw function, however, i'm not implementing gettransform function transformable, don't know how access this.
can please show me how use interfaces function supplied here?
thanks.
interfaces not substitute inheritance.
with interfaces "inherit", well... interface. is, bunch of signatures of public members (methods, properties). can't inherit meaningful substance interface. when choose implement interface, put burden going implement members of interface. can in design stage, not reuse implementation exists in class.
it fact you can inherit multiple classes in c++, , fact you can implement multiple interfaces in c#. the latter not c# way of getting former. 2 different properties, both true, 1 of c++ language , other of c# language , .net platform altogether.
Comments
Post a Comment