![]() |
|
#1
|
|||
|
|||
Selecting datatype at runtimeHello,
is it possible to choose the type of variable at runtime in c++ for example CPP / C++ / C Code:
or actually I want to define a templated variable with different types according to the input in a function CPP / C++ / C Code:
Last edited by admin : 22-Jan-2009 at 04:58.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
||||
|
||||
Re: Selecting datatype at runtimeTemplate types are known at compile time and are probably not what you really want.
You may want to explore RTTI (runtime type information). However, it is unclear what you really want to do based on the information that you've provided. Your example, even if successful doesn't do anything meaningful, so it is useless. Useless in what it "does" (if it worked) and useless at conveying your real meaning. If you mean to say that you want to pass in a variable that describes the "type information," to a function and have it return a new instance of the type, fine. What you've described can be implemented in a few different ways. the VARIANT type popular in Visual Basic is a good example of how to implement such a beast. In C it is implemented using a union of several types and, of course, an identifier that identifies the type to "the world." How about rephrasing what you want and add perhaps more about what you want to do with it so that we'll better know how to respond? MxB |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Runtime Error 21 | n10doefrk | Computer Software Forum - Windows | 3 | 26-Sep-2008 04:56 |
| How to Suppress Runtime Error Dialog Box | js_63042 | MS Visual C++ / MFC Forum | 0 | 21-Jul-2008 14:30 |
| How to change menu label at runtime | suja | FLTK Forum | 4 | 10-Jul-2007 20:30 |
| how to increase the font size at runtime | banur22 | MS Visual C++ / MFC Forum | 1 | 21-Apr-2005 07:37 |
| Free copy of Runtime Revolution | crystalattice | Open Discussion Forum | 0 | 29-Dec-2004 16:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The