Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
May 16, 2002 Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Does D have Static Virtual Member Functions? It would be nice if it did. I know and have used many workarounds in the past in C++ but they all have drawbacks. If it doesn't, there's probably some good reason, so explain that. |
May 16, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | "anderson" <anderson@firestar.com.au> wrote in message news:abvm8j$1iaj$1@digitaldaemon.com... > Does D have Static Virtual Member Functions? It would be nice if it did. I Could you please explain what are virtual (called via vtable) static functions for? |
May 16, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | It's hard to think of an easy example (not that there aren't heaps of them). In one case I need to register a list of classes as numbers, which made for easy saving, and a host of other cool things. Perhaps you could suggest a better way of doing this, but I still think static virtual member function would be cool (and parhaps they're aready in D). ie (C++ code) //registers all classes with a private number void registerElements() { element * Temp; //Elements for (int n=1; n<getMaxElements(); n++) { //Create Element (won't be need if static virtual member functions were supported) Temp = getElement(n); //If it exists if (Temp) { //Pass it's number Temp->setClassID(n); //Destroy Item delete Temp; } } } //Returns a new unit for the selected number //Note, probably should make more generic //When ever a new object needs to be defind, simply use getElement (parhaps should be called newElement) element * getElement(int Number) { switch (Number) { case vertexEL::getClassID(): return new vertexEL(); case lineEL::getClassID(): return new lineEL(); default: return NULL; } } also the element extend this class class IDClass { private: public: IDClass(); virtual ~IDClass(); //Returns the very important Class ID. int getClassID(); void setClassID(int ID); //Must be used in each sub class, returning a pointer to a static integer value //More ugly c++ code to support static virtual member function virtual int * classIDPtr()=0; }; The example above was for a drawing package, primitives where extended from element. This allows for many comminalties to be definded once and used for every class. Saving/undoing is a brezze and can be done in clusters. The object could also define there own properties (dynamicly), but that's another story. This way programmers could work individually on the project, adding extended classes into the program, test them and everything. Once the new class was definded, it would be issued with a number (by the project's element number keeper) and added to the main list of classes for that type (the above code was modified slightly to support that). Admitly the register part in the above code could be included as part of the static constructor code in D, but if it was need to be dynamic... D would also improve apone many other aspects of the code above (as I'm sure some of you will point out). Using virtual static member functions would make the above example much easier. There are documents on work arounds for static virtual member functions for C++ (the above uses one of them), and I don't see why there should be documents on workarounds, if it isn't a feature that should have been included. It would also be cool is static virtual properties (ie int) was supported. I may be hard to imagine, but this way of coding has made multi-programming much easier. Thanks, for taking the time to read this long Doc. "Pavel Minayev" <evilone@omen.ru> wrote in message news:abvt2u$1nut$1@digitaldaemon.com... > "anderson" <anderson@firestar.com.au> wrote in message news:abvm8j$1iaj$1@digitaldaemon.com... > > > Does D have Static Virtual Member Functions? It would be nice if it did. I > > Could you please explain what are virtual (called via vtable) static > functions for? > > |
May 16, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | I've made mistake in the previous code, should be, element * getElement(int Number) { switch (Number) { case 0: return new vertexEL(); case 1: return new lineEL(); default: return NULL; } } (I was thinking in curves :) ) And just when the I-net disconnects. Grrrrrr "Pavel Minayev" <evilone@omen.ru> wrote in message news:abvt2u$1nut$1@digitaldaemon.com... > "anderson" <anderson@firestar.com.au> wrote in message news:abvm8j$1iaj$1@digitaldaemon.com... > > > Does D have Static Virtual Member Functions? It would be nice if it did. I > > Could you please explain what are virtual (called via vtable) static > functions for? > > |
May 16, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | I've made mistake in the previous code, should be, element * getElement(int Number) { switch (Number) { case 0: return new vertexEL(); case 1: return new lineEL(); default: return NULL; } } (I was thinking in curves :) ) And just when the I-net disconnects. Grrrrrr "anderson" <anderson@firestar.com.au> wrote in message news:ac02vo$1t98$1@digitaldaemon.com... > It's hard to think of an easy example (not that there aren't heaps of them). > > In one case I need to register a list of classes as numbers, which made for > easy saving, and a host of other cool things. Perhaps you could suggest a better way of doing this, but I still think static virtual member function would be cool (and parhaps they're aready in D). > > ie (C++ code) > > //registers all classes with a private number > void registerElements() > { > element * Temp; > //Elements > for (int n=1; n<getMaxElements(); n++) > { > //Create Element (won't be need if static virtual member functions were > supported) > Temp = getElement(n); > > //If it exists > if (Temp) > { > //Pass it's number > Temp->setClassID(n); > //Destroy Item > delete Temp; > } > } > } > > //Returns a new unit for the selected number > //Note, probably should make more generic > //When ever a new object needs to be defind, simply use getElement (parhaps > should be called newElement) > element * getElement(int Number) > { > switch (Number) > { > case vertexEL::getClassID(): return new vertexEL(); > case lineEL::getClassID(): return new lineEL(); > default: return NULL; > } > } > > also the element extend this class > > class IDClass > { > private: > > public: > IDClass(); > virtual ~IDClass(); > > //Returns the very important Class ID. > int getClassID(); > void setClassID(int ID); > > //Must be used in each sub class, returning a pointer to a static integer > value > //More ugly c++ code to support static virtual member function > virtual int * classIDPtr()=0; > }; > > > The example above was for a drawing package, primitives where extended from > element. This allows for many comminalties to be definded once and used for > every class. Saving/undoing is a brezze and can be done in clusters. The object could also define there own properties (dynamicly), but that's another story. > > This way programmers could work individually on the project, adding extended > classes into the program, test them and everything. Once the new class was definded, it would be issued with a number (by the project's element number > keeper) and added to the main list of classes for that type (the above code > was modified slightly to support that). Admitly the register part in the above code could be included as part of the static constructor code in D, but if it was need to be dynamic... D would also improve apone many other aspects of the code above (as I'm sure some of you will point out). > > Using virtual static member functions would make the above example much easier. There are documents on work arounds for static virtual member functions for C++ (the above uses one of them), and I don't see why there should be documents on workarounds, if it isn't a feature that should have been included. > > It would also be cool is static virtual properties (ie int) was supported. > > I may be hard to imagine, but this way of coding has made multi-programming > much easier. > > Thanks, for taking the time to read this long Doc. > > "Pavel Minayev" <evilone@omen.ru> wrote in message news:abvt2u$1nut$1@digitaldaemon.com... > > "anderson" <anderson@firestar.com.au> wrote in message news:abvm8j$1iaj$1@digitaldaemon.com... > > > > > Does D have Static Virtual Member Functions? It would be nice if it did. > I > > > > Could you please explain what are virtual (called via vtable) static > > functions for? > > > > > > |
May 16, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | "anderson" <anderson@firestar.com.au> wrote in message news:ac02vo$1t98$1@digitaldaemon.com... > It's hard to think of an easy example (not that there aren't heaps of them). > > In one case I need to register a list of classes as numbers, which made for > easy saving, and a host of other cool things. Perhaps you could suggest a better way of doing this, but I still think static virtual member function would be cool (and parhaps they're aready in D). I see now. But I don't really see any other use for this but the creation of objects of class known only at run-time. If this is the case, we just need a built-in function, that'd take a ClassInfo, and return the new object of that class... I made this proposal lots of times already. This is what is usually called "virtual constructor". |
May 17, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | There are such cases where "static virtual member functions" (or parhaps "virtual static member functions" ) are need. You don't know how useful they are until you use them. In something like D, I'd expect the virtual part to be default as it is with other things. Here's some else how had a simular problem, http://cpptips.hyperformix.com/cpptips/virt_static_memb "Pavel Minayev" <evilone@omen.ru> wrote in message news:ac0dov$26td$1@digitaldaemon.com... > "anderson" <anderson@firestar.com.au> wrote in message news:ac02vo$1t98$1@digitaldaemon.com... > > It's hard to think of an easy example (not that there aren't heaps of > them). > > > > In one case I need to register a list of classes as numbers, which made > for > > easy saving, and a host of other cool things. Perhaps you could suggest a > > better way of doing this, but I still think static virtual member function > > would be cool (and parhaps they're aready in D). > > I see now. But I don't really see any other use for this but the > creation of objects of class known only at run-time. If this is > the case, we just need a built-in function, that'd take a ClassInfo, > and return the new object of that class... I made this proposal > lots of times already. This is what is usually called "virtual > constructor". > > |
May 17, 2002 Re: Static Virtual Member Functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | "anderson" <anderson@firestar.com.au> wrote in message news:ac1pk3$b76$1@digitaldaemon.com... There are such cases where "static virtual member functions" (or parhaps "virtual static member functions" ) are needed. You don't know how useful they are until you've used them. In something like D, I'd expect the virtual part to be default, as it is with other things. (I seem to be missing droping alot of letters lately) > Here's some else how had a simular problem, http://cpptips.hyperformix.com/cpptips/virt_static_memb > > "Pavel Minayev" <evilone@omen.ru> wrote in message news:ac0dov$26td$1@digitaldaemon.com... > > "anderson" <anderson@firestar.com.au> wrote in message news:ac02vo$1t98$1@digitaldaemon.com... > > > It's hard to think of an easy example (not that there aren't heaps of > > them). > > > > > > In one case I need to register a list of classes as numbers, which made > > for > > > easy saving, and a host of other cool things. Perhaps you could suggest > a > > > better way of doing this, but I still think static virtual member > function > > > would be cool (and parhaps they're aready in D). > > > > I see now. But I don't really see any other use for this but the > > creation of objects of class known only at run-time. If this is > > the case, we just need a built-in function, that'd take a ClassInfo, > > and return the new object of that class... I made this proposal > > lots of times already. This is what is usually called "virtual > > constructor". > > > > > > |
Copyright © 1999-2021 by the D Language Foundation