help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

warning with function templates


From: Christian Christmann
Subject: warning with function templates
Date: Sat, 16 Jul 2005 14:58:17 +0200

Hi,

when I run this code:

#include <iostream>
using namespace std;

template <class T>
T GetValue(int a)
{
    if (a = 1)
        return 1;
    else
        return 2.55; // line 11
}

int main()
{
    int a = GetValue<int>(1); // line 16
    cout << "\nInt a : " << a << endl;

    double b = GetValue<double>(2);
    cout << "\nDouble b: " << b << endl;

    return 0;
}


I get the gcc warning:
temp.cpp: In function `T GetValue(int) [with T = int]':
temp.cpp:16:   instantiated from here
temp.cpp:11: warning: converting to `int' from `double'


Why? 
Line 16 should not be reached when the function is called
from line 11.

Is there any way to avoid this warning?

Thank you
Chris


reply via email to

[Prev in Thread] Current Thread [Next in Thread]