Answer the question
In order to leave comments, you need to log in
Using typeid in a template class
here is the part of the class with the function in question
template <class W>
class CBuffer
{ private:
W *arr;
int len;
int nowIndex;
W & operator[](unsigned int i)
{
if (i<len) {
return arr[i];
}
}
void getElement(TListBox* LB)
{
if(typeid(arr)==typeid(CWeather*)){
W tmp;
LB->Items->Clear();
for (int i = 0; i <len; i++) {
if(!(arr[i]==tmp)){
LB->Items->Add(AnsiString("Температура: ") + arr[i].getsTemperature());
LB->Items->Add("Давление: " +arr[i].getsPressure());
LB->Items->Add("Скорость ветра: " + arr[i].getsWindSpeed());
LB->Items->Add("\Направление ветра: "+arr[i].getsWindDirection());
LB->Items->Add("---------------------------");
}
}
}
if (typeid(arr)==typeid(short*))
{
LB->Items->Clear();
for (int i = 0; i <len; i++) {
LB->Items->Add(arr[i]);
}
}
}
CBuffer<CWeather> *buf = new CBuffer<CWeather>();
CBuffer<short> *buf2 = new CBuffer<short>();
Answer the question
In order to leave comments, you need to log in
typeid of the template class
First, as already mentioned, in this case, specialization should be used.
And secondly, there is such a thing as www.cplusplus.com/reference/type_traits/is_same
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question