VB-Classes

punk
12-10-2000, 07:18 PM
I have a class called "Item".. then I did the following
Dim "something" as new Item
Dim "something2 as new item
So how can I count how many "somethings" I created?

It wil be much better if I could count like this
Dim apple as new item
Dim apple2 as new item
Dim banana as new item
"There is 2 apples and 1 banana"
Sounds hard!?


Punkrock on my veins..... ARRGGHHUU !

CodingFiend
12-18-2000, 12:21 PM
You could create a class factory. For instance, create your Item class, then create an ItemFactory class. Create one instance of the ItemFactory, and have a function within in called, say, CreateItem() that creates a new item in an ItemFactory private collection of Items then returns a reference to the just-created Item object. Have another function that simply gets the collection count and returns it. On ItemFactory destruction, simply iterate through your collection and set each Item object to nothing (don't think this is necessary, but c/c++ thinking is hard to ignore). hth.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum