开发平台(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
感谢大大拨冗观看