Oxygen Basic
		Programming => Problems & Solutions => Topic started by: helloworld on June 24, 2017, 09:52:00 PM
		
			
			- 
				How to declare a container of (pointers to) an abstract class/type (aka interface)?
 That is the equivalent of C++:
 
 struct Interface
 {
 virtual void f()=0;
 };
 struct A : Interface
 {
 void f(){}
 };
 struct B : Interface
 {
 void f(){}
 };
 int main()
 {
 Interface* ic[]={new A(), new B()};
 }
 
- 
				
 It's quite complicated!
 
 '2017-06-25 T 08:48:54
 'ARRAY OF VIRTUAL OBJECTS
 '
 extern
 
 'typical interface
 'method act(){print "act"}
 '...
 
 class ca
 method act(){print "act A"}
 method constructor(){}
 method destructor(){}
 end class
 
 class cb
 method act(){print "act B"}
 method constructor(){}
 method destructor(){}
 end class
 
 extern virtual
 
 class interface
 method act()
 end class
 
 end extern
 
 new ca a1 : ?a1=@ca_table
 new cb b1 : ?b1=@cb_table
 
 typedef interface * pinterface
 indexbase 1
 pinterface vc[100]
 @vc[]={@a1,@b1}
 
 vc[1].act 'act A
 vc[2].act 'act B
 ...
 del a1
 del b1
 
- 
				Great!
			
- 
				Hi Charles,
 
 new ca a1 : ?a1=@ca_table
 new cb b1 : ?b1=@cb_table
 
 
 I assume _table is somehow built-in with Oxygenbasic and creates a pointer to a function table? Can this construct only be used with object oriented programming?
 
 I am also not sure about the purpose of ?a1. Does this create an index? It seems to be different from @a1.
 
 Roland
- 
				Hi Roland,
 
 class_table is only created when a class contains methods and other static members, but not for extern virtual objects.
 
 External objects use method table pointers,  and currently, non-virtual  objects call methods use the table directly.
 
 The '?' symbol is another way of casting (sys)
- 
				This has similar functionality without requiring pointers.
 
 Instead of building an array of virtual object pointers, a class is used to contain the objects.
 
 members is used to invoke  methods in common of all the contained members with a single statement.
 
 method act(){members.act}
 method constructor(){members.constructor}
 method destructor(){members.destructor}
 
 
 '2017-06-30 T 07:29:27
 'MEMBERS.METHOD()
 
 class ca
 int v
 method act(){members.act : print "act A"}
 method constructor(){}
 method destructor(){}
 end class
 
 class cb
 int v
 method act(){members.act : print "act B"}
 method constructor(){}
 method destructor(){}
 end class
 
 'FLAT MEMBERS
 class cc
 has ca ca1,ca2
 has cb cb1,cb2
 method act(){members.act}
 method constructor(){members.constructor}
 method destructor(){members.destructor}
 end class
 
 new cc c
 c.act
 del c