It is possible to choose template parameter in runtime?
when i try to construct an object wich has template parameter
merse
0
Junior Poster
Recommended Answers
Jump to PostNo but you can adjust I guess.
string type; cout<<"Choose Type (int,string,float) : "; cin >> type; if(type == "string"){ myClass<string> stringClass; //do stuff } else if(type == "float"){ myClass<float> floatClass; //do stuff } //and so on.
But C++ does not runtime templates.
Jump to PostOf course dude!! The following code should help...
//This program finds the maximum of two inputs. //However, the data type for the inputs is decided by the user.. at runtime!! #include<iostream> using namespace std; template<class T> T maximum(T& var1,T& var2){ if(var1>var2){ cout<<var1<<" is the greatest!!"<<endl; return var1; …
Jump to PostWhy exactly do you need the runtime template parameter ?
And check your spelling for sizeof.
All 11 Replies
mrnutty
761
Senior Poster
merse
0
Junior Poster
tkud
0
Posting Whiz in Training
merse
0
Junior Poster
mrnutty
761
Senior Poster
merse
0
Junior Poster
mrnutty
761
Senior Poster
merse
0
Junior Poster
mrnutty
761
Senior Poster
merse
0
Junior Poster
mrnutty
761
Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.