inheritance - C# executing function in inheriting classes from main class array -


sorry in advance english.

i'm doing scripts in unity , want achieve is:

i have multiple classes (b1, b2, b3) , every 1 of them inherit class. in code have container objects, contain b classes. class , b classes have function called myfunction() , there problem: when want call function on object of class i.e. b2, when in vector class objects, when call myfunction(), there executed version a, not b2. tried solve problem in best way could, ended "if b1, ... else if b2, ..." type of solution not want.

as example of ugly solution (used in immaded() ), link scripts, without every line not needed in example:

http://pastebin.com/4by0rkbn

thank effort in advance.

as per this msdn page, need declare myfunction method virtual:

the virtual keyword used modify method, property, indexer, or event declaration , allow overridden in derived class. example, method can overridden class inherits it.

public class {     public virtual void myfunction()      {         ...     } } 

then in sub classes so:

public class b : {     public override void myfunction()     {         ...     } } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -