PDA

View Full Version : classes question



ygfperson
05-12-2003, 05:53 PM
I have two classes: Function and Function_Definition. The class Function_Definition contains a static member of a vector of Function_Definition pointers. Every function has a name (in the form of a string), and so do the function_definitions. Every function_definition name is unique.

How do I connect a function to a function_definition based on the name? I feel like I need a global set of names, but that seems... not elegant.

Eibro
05-12-2003, 06:46 PM
Originally posted by ygfperson
I have two classes: Function and Function_Definition. The class Function_Definition contains a static member of a vector of Function_Definition pointers. Every function has a name (in the form of a string), and so do the function_definitions. Every function_definition name is unique.

How do I connect a function to a function_definition based on the name? I feel like I need a global set of names, but that seems... not elegant. Sounds like a job for std::map. You could do std::map<std::string, int>, int being index into the vector of Function_Definition pointers, or you could even map a string to a function pointer if you wanted.

ygfperson
05-12-2003, 08:11 PM
That's not my issue... my issue is, where do I store this in an OOP-friendly manner? Is it a good idea to store it as a static member of class A and access it from class B? (A and B being arbitrary classes)

Eibro
05-12-2003, 08:56 PM
Originally posted by ygfperson
That's not my issue... my issue is, where do I store this in an OOP-friendly manner? Is it a good idea to store it as a static member of class A and access it from class B? (A and B being arbitrary classes) Ah, sorry... couldn't make out what you were saying. Anyway, yes, a static member of class A sounds like a good solution (possibly make it private or protected, and make B a friend of A)