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 PostWhy exactly do you need the runtime template parameter ?
And check your spelling for sizeof.
Jump to PostIn your example you have a function template: maximum<>,
but what I have is a template class myclass<>!
And my problem is that the classes have different member functions
and I cannot use them!
For example my template parameter can be (I would like to be)
double or my wn …
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.