Template instantiation issue on Dev C++ compiler.



 DEVELOP > c-Plus-Plus > Template instantiation issue on Dev C++ compiler.

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "param"
Date: 14 Jan 2008 02:18:27 AM
Object: 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();
}
.

User: "Alf P. Steinbach"

Title: Re: Template instantiation issue on Dev C++ compiler. 14 Jan 2008 02:35:06 AM
* 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?
.

User: ""

Title: Re: Template instantiation issue on Dev C++ compiler. 14 Jan 2008 02:36:58 AM
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
.


  Page 1 of 1

1

 


Related Articles
Sun C++ compiler: How to change template instantiation directory
Template instantiation on HP aCC compiler
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines
Template specialization problem - compiler bug or my fault?
How does the compiler interpret a template argument (reference vs. non-reference) ?
New compiler chokes on template class
what to do with template classes in template unsupported compiler ?
static function template problem on sun compiler
convert binary to decimal in template at compiler time.
a compiler error with template function
template implementation not seen by the compiler
template problem with ostream operator (Borland compiler)
Huge compilation time of template based sources (AIX 5.2, VA C++ 6 compiler)
template problem with MIPSpro compiler
Any new compiler support the `export` of C++ template?
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER