Bonjour,

j'ai du mal à poster un message. Je ne sais le faire qu'ici.

Voilà mon problème : je code en C++ avec QTCreator sous Windows ; et je veux utiliser typeid(), mais le compilateur m'affiche des warnings (mais le code compile et s'exécute toutefois) du style <<format '%d' expects argument of type 'int' but argument 3 has type 'double'>> et ceci pour chaque ligne. Savez-vous comment faire pour faire disparaître les warnings du compilateurs svp ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <typeinfo>    // typeid
 
template <class T>
void List<T>::print() const
{
  for (ent i = 0 ; i < _size ; ++i)
  {
         if (typeid(T) == typeid(char       ) || typeid(T) == typeid(unsigned char     )) printf("List[%lld] = %c\n"  ,i,_list[i]);
    else if (typeid(T) == typeid(short      ) || typeid(T) == typeid(unsigned short    )) printf("List[%lld] = %hd\n" ,i,_list[i]);
    else if (typeid(T) == typeid(int        ))                                            printf("List[%lld] = %d\n"  ,i,_list[i]);
    else if (                                    typeid(T) == typeid(unsigned int      )) printf("List[%lld] = %u\n"  ,i,_list[i]);
    else if (typeid(T) == typeid(long       ) || typeid(T) == typeid(unsigned long     )) printf("List[%lld] = %ld\n" ,i,_list[i]);
    else if (typeid(T) == typeid(long long  ) || typeid(T) == typeid(unsigned long long)) printf("List[%lld] = %lld\n",i,_list[i]);
    else if (typeid(T) == typeid(float      ) || typeid(T) == typeid(double            )) printf("List[%lld] = %g\n"  ,i,_list[i]);
    else if (typeid(T) == typeid(long double))                                            printf("List[%lld] = %Lg\n" ,i,_list[i]);
    else                                                                                 {printf("Format not supported to print List<T>\n"); return;}
  }
}
 
 
dans le main :
{
  List<char> charToto = List<char>(0); charToto << 'a' << 'b' << 'c';
  List<double> doubleToto = List<double>(0); doubleToto << 6.87 << 2.35 << 8.4865;
  charToto.print();
  doubleToto.print();
}
Merci de l'avoir déplacé. J'ai cherché toute la matinée et je viens de trouver une solution. je fais un cast devant le troisième argument du printf. Désolé pour vous avoir sollicité.

Sujet résolu. Merci beaucoup.