Template instantiation issue on Dev C++ compiler.

P

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'

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();
}
 
A

Alf P. Steinbach

* 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
 
J

jkherciueh

param said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top