PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Template instantiation issue on Dev C++ compiler.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Template instantiation issue on Dev C++ compiler.

Réponse
 
LinkBack Outils de la discussion
Vieux 14/01/2008, 08h18   #1
param
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Template instantiation issue on Dev C++ compiler.

Hi guys,

The following code is not being compiled. I am getting this error
message:

C:\Dev-Cpp\tmp2Params.cpp In function `T1 maxx(const T1&, const T2&)
[with T1 = int, T2 = double]':
12 C:\Dev-Cpp\tmp2Params.cpp instantiated from here
7 C:\Dev-Cpp\tmp2Params.cpp [Warning] converting to `int' from
`double'

Any idea, what i am missing here. i am purposly passing the arguments
as int and double i.e. (4,5.5 ).The compiler is Dev C++.

#include <iostream>
using namespace std;

template <class T1, class T2 >
T2 maxx (T1 const& a, T2 const& b)
{
return a > b ? a:b;
}

int main( int argc, char ** argv)
{
cout << " Max: " << maxx(4, 5.5) << endl;

getchar();
}
  Réponse avec citation
Vieux 14/01/2008, 08h35   #2
Alf P. Steinbach
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Template instantiation issue on Dev C++ compiler.

* param:
> Hi guys,
>
> The following code is not being compiled. I am getting this error
> message:
>
> C:\Dev-Cpp\tmp2Params.cpp In function `T1 maxx(const T1&, const T2&)
> [with T1 = int, T2 = double]':
> 12 C:\Dev-Cpp\tmp2Params.cpp instantiated from here
> 7 C:\Dev-Cpp\tmp2Params.cpp [Warning] converting to `int' from
> `double'


This is not a compilation error, it's a warning.


> Any idea, what i am missing here. i am purposly passing the arguments
> as int and double i.e. (4,5.5 ).The compiler is Dev C++.
>
> #include <iostream>
> using namespace std;
>
> template <class T1, class T2 >
> T2 maxx (T1 const& a, T2 const& b)
> {
> return a > b ? a:b;
> }
>
> int main( int argc, char ** argv)
> {
> cout << " Max: " << maxx(4, 5.5) << endl;
>
> getchar();
> }


This is not the code you compiled.

However, if you swap the actual arguments, or make the result type T1,
you can reproduce the warning, which is due to return expression of type
double being converted to function result type int.


Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
  Réponse avec citation
Vieux 14/01/2008, 08h36   #3
jkherciueh@gmx.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Template instantiation issue on Dev C++ compiler.

param wrote:

> Hi guys,
>
> The following code is not being compiled. I am getting this error
> message:
>
> C:\Dev-Cpp\tmp2Params.cpp In function `T1 maxx(const T1&, const T2&)
> [with T1 = int, T2 = double]':
> 12 C:\Dev-Cpp\tmp2Params.cpp instantiated from here
> 7 C:\Dev-Cpp\tmp2Params.cpp [Warning] converting to `int' from
> `double'


Note that the compiler claims the signature of the function to be:

T1 maxx(const T1&, const T2&)
^^

This does not match your code below.


> Any idea, what i am missing here.


Maybe some include gets an old version of some file.


> i am purposly passing the arguments
> as int and double i.e. (4,5.5 ).The compiler is Dev C++.
>
> #include <iostream>
> using namespace std;
>
> template <class T1, class T2 >
> T2 maxx (T1 const& a, T2 const& b)
> {
> return a > b ? a:b;
> }
>
> int main( int argc, char ** argv)
> {
> cout << " Max: " << maxx(4, 5.5) << endl;
>
> getchar();
> }



Best

Kai-Uwe Bux
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,74800 seconds with 11 queries