ecsv38@castle.ed.ac.uk (S Manoharan) (06/27/90)
In article <23694@uflorida.cis.ufl.EDU> sml@beach.cis.ufl.edu (Shein-Fong Law) writes: > > I am trying to implement an object idendity generator for my database >project. I want to assign an instance i.d (i.i.d) for each object created. The >format of i.i.d is a concatenation of class i.d (c.i.d) and object i.d (o.i.d). >All the objects belonging to the same class will have the same c.i.d but >different (unique) o.i.d's. Internally, the identifiers can be just unsigned >integers. > > Also, I want the creation of such identifiers to be known by the system only >(in this case, me). Of course, the design should be object-oriented. > One possible way could be: class Root { private: char *cname; int oid; protected: void name(char *const s) { cname = s; } public: Root(char * = 0); int id() { return oid; } char *name() const { return cname; } int class_id() { return (int)cname; } }; Root::Root(char *s) // should not be inline { static int ob = 0; oid = ob++; cname = s ? s : "Root"; } class Leaf : public Root { public: Leaf() : ("Leaf") { /* */ } }; All objects, whether they belong to the same class or not, will have different ids. Class names are to be given whenever you derive a class from Root. (This will also help in debugging!) Address of class names can serve as class ids. Manoharan.