I want to have a data member that points to any of a number of predefined types. How is this possible?
Say if I want it to point to an int I can set it to point to an int, and I can have a function which returns the type of a parameter etc. Is that possible also?
Thanks in advance.
Edit: I just compiled the following code.... to my surprise it compiled.
But what does it do actually?
No, there's nothing akin to pointers to types in C++. There might be alternative solutions, but that requires knowing what you're trying to do.
But what does it do actually?
Your function foo takes a parameter of an arbitrary type and returns an object of the same type, which instance.itemType will be converted to if possible.
well what i was trying to do was change the implementation of my matrix class, which has a datamember int mymatrix[MAXSIZE][MAXSIZE]; as a container and int myRows and int myCols for size parameters. problem is, to use a simple 3x3 matrix, you have to create a MAXSIZExMAXSIZE matrix in each constructor, which is time consuming, especially for repetetive calls.
I was thinking of having something like 3 datamembers, and a pointer to one of those 3 datamembers.
That way in order to keep the functionalizy of resizing a matrix later, you woudln't have to necessarily create a maxsize x maxsize sized matrix even for creating a small matrix...
Your matrix class should not have a fixed number of rows and columns. Use some dynamic memory allocation. This will take a little careful indexing since you cannot dynamically allocate a variable-sized multi-dimensional array.