我有這段代碼一類(這是一個片段):之間的轉換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