On Wednesday, 16 May 2012 at 02:01:25 UTC, Stephen Jones wrote:
Using Object gives exactly the same problem as the Object super class does not have vcount variable. Casting is not a solution because the reason for throwing different sorts of widgets into a single array was so I did not have to track what each type of object was; not tracking what each object in the array is I have no means of knowing what to cast each Widget in the array to.

You'd just try to cast each object into the classes you want. Like he said, it'll be null if the casting failed. Otherwise, it'll be the object and you can get the vcount.

However, I have to ask ... is it that all Widgets need to have this vcount? If so, the proper way to do this is user-defined properties:
http://dlang.org/property.html

So your Widget class might look like this:
class Widget {
    public @property int vertCount();    // getter
    public @property int vertCount(int); // setter
    void draw(){}
}


If some one knows void pointer syntax that would be helpful. As I understand it there is a type called size_t that takes the address of as a a value. Can I make an array of these and simply initialize each with &button1, &cursor, etc? Also, how is size_t freed?

This is _not_ a solution you want at all. Converting pointers to integers in D is undefined behavior and size_t is not a type for that (it's used to hold indices for arrays and such).

If you convert a pointer to an int and get rid of the pointer, the Garbage Collector will not see any references to your object anymore and will reap your object.

Reply via email to