surcharge et déduction template
Bonjour,
je n'arrive pas pouvoir détecter le paramètre d'une fonction membre surchargée (version non const et version const) erreur C2914 ; je suis sous VS 2005 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| struct TTest
{
string txt;
const string & get_txt() const
{ return txt; }
string & get_txt()
{ return txt; }
};
template<typename TReturn>
void tmp_funct(TReturn (TTest::* )() const)
{ //...
}
int _tmain(int argc, _TCHAR* argv[])
{
tmp_funct( &TTest::get_txt ); // erreur C2914
//...
} |
Si il est logique d'avoir cette erreur pour
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| struct TTest
{
int f(int)
{ /* ... */ }
string f(const char *)
{ /* ... */ }
};
template<typename TResult, typename T>
void tmp_funct(TResult (TTest::* )(T) )
{ //...
}
int _tmain(int argc, _TCHAR* argv[])
{
tmp_funct( &TTest::f ); // quel TTest::f prendre ? => erreur C2914
//...
} |
elle n'as pas lieu avec
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| struct TTest
{
int f(int)
{ /* ... */ }
string f(const char *)
{ /* ... */ }
};
template<typename TResult>
void tmp_funct(TResult (TTest::* )(int) )
{ //...
}
int _tmain(int argc, _TCHAR* argv[])
{
tmp_funct( &TTest::f ); // Ok
//...
} |
Or dans le cas qui m'intéresse, la version const est bien demandée. Est-ce un restriction (bug?) du compilateur ou du langage ?