|
皆さん
いつもお世話になっております。
またご指導頂ければ幸いです。
OS: Windows XP
IDE:MS visual studio
テンプレット関数を使おうとしたら変な現象が起きています。
これは仕様であるはずないと思ってみんさんの英知を借りたいです。
下記ようような関数テンプレットの定義があるとします。
template<typename T> short tempQ (short x, short y, short width, short height, double lowthre)
{
......
}
いくつか上記のテンプレット関数をコールする関数を定義しておきます:
short doChar(short x, short y, short width, short height, double lowthre)
{
return tempQ <unsigned char>(x, y, width, height,lowthre);
}
short doShort(short x, short y, short width, short height, double lowthre)
{
return tempQ <short>(x, y, width, height,lowthre);
}
short doInt(short x, short y, short width, short height, double lowthre)
{
return tempQ <int>(x, y, width, height,lowthre);
}
short doFloat(short x, short y, short width, short height, double lowthre)
{
return tempQ <float>(x, y, width, height,lowthre);
}
すると、
doChar(..)、doShort(..)、doInt(..)のどれを実行しても
必ずソース上では最後に表しているtemplet関数が実行されます。
例えば、doChar(..)を実行しようとしても、
tempQ <unsigned char>(x, y, width, height,lowthre)の本体に入れず、
tempQ <float>(x, y, width, height,lowthre)の本体に入る。
順番変えて、例えば、最後に定義した関数doFloat(..)の中の
「return tempQ <float>(x, y, width, height,lowthre);」を
「tempQ <int>(x, y, width, height,lowthre);」に置き換えたら、
今度はdoChar(..)、doShort(..)、doFloat(..)のいずれを実行しても
いつもtempQ <int>(x, y, width, height,lowthre)が実行されます。
結構可笑しいですよね
どうぞ宜しくお願い致します
|