C++ object instantiation..
-
Hi. I would like to be able to instantiate an object based on some attribute. ie) I would like to be able to tell a function to create a object based on some value. I do not mean a simple switch trawling through a range of int or char values, but to be able to call a function with an argument that can be used to create an object of a specified type. Is it possible to create an object based on an indirection, other than a pointer to an already exisiting object of the same kind. Any advice would be very welcome. James
-
Hi. I would like to be able to instantiate an object based on some attribute. ie) I would like to be able to tell a function to create a object based on some value. I do not mean a simple switch trawling through a range of int or char values, but to be able to call a function with an argument that can be used to create an object of a specified type. Is it possible to create an object based on an indirection, other than a pointer to an already exisiting object of the same kind. Any advice would be very welcome. James
Hi James, the technique you're after is oftenly called a virtual constructor or factory method; google for these terms to get some info. If you have trouble implmenting this, do not hesitate to come back for more help. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Hi James, the technique you're after is oftenly called a virtual constructor or factory method; google for these terms to get some info. If you have trouble implmenting this, do not hesitate to come back for more help. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hi. Thanks very much. I am after the type of effect that you can get using an array of pointers to functions. I will check out the web, as you suggest. Thanks. James.