Is there any way to declare a template class object with a datatype that is defined by the user in the main() function?
If yes, how? If no, why and is there an alternative?
For example:
template <class type>
class myclass
{
type myint;
type mydouble;
type mychar;
type mystring;
public:
void myint(type);
void mydouble(type);
void mychar (type);
void mystring (type);
};
int main ()
{
// how can i get data for all different datatype
// using only one template class object
// something like myclass<type>oject;
object.myint() = 10;
object.mydouble()=3.5;
object.mychar()= 'c';
object.mystring = "myname";
//obviously this won't work.
How can I make this work?
I really do not want to use one object for each of them.
Aucun commentaire:
Enregistrer un commentaire