開發平台(Platform): (Ex: Win10, Linux, ...)
win7
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
vc2010
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
如題
餵入的資料(Input):
T = Point, K = float
T = PointF, K = double
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
warning C4244
將 float 轉 int 可能導致資料遺失
將 double 轉 float 可能導致資料遺失
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
template <typename T, typename K>
void func(T a, K b, T &c)
{
c.X = a.X * b;
}
補充說明(Supplement):
原本以為 decltype 可以幫上忙, 但似乎不能這樣寫...
c.X = (decltype c.X) (a.X * b);
正確寫法
c.X = (decltype (c.X)) (a.X * b);
看到 warning 很煩躁...
我知道T, K不能亂丟型態進去
因此我想要把泛型做成 class private
然後 public 指定的T K
感謝大大撥冗觀看