我有这段代码一类(这是一个片段):之间的转换2模板
template<typename T>
class Pos2 {
public:
T x, y;
Pos2() : x(0), y(0) {};
Pos2(T xy) : x(xy), y(xy) {};
Pos2(T x, T y) : x(x), y(y) {};
};
现在,我也得到了2种类型定义它:
typedef Pos2<pos_scalar> Pos;
typedef Pos2<size_scalar> Size;
一切正常,但是当我这样做:
Pos p(5.5, 6.5);
Size s(3, 8);
p = s;
我得到这个错误:
error: conversion from ‘Size {aka Pos2<short int>}’ to non-scalar type ‘Pos’ requested
这是有道理的,但我想知道如何解决它= P
什么是'Type2'?你的意思是'typename Type2'? – 0x499602D2