有人可以解釋爲什麼這不起作用嗎?wchar_t的模板專精
template < typename T > struct tester { static const size_t value = 0; };
template <> struct tester<char> { static const size_t value = 1; };
template <> struct tester< unsigned short > { static const size_t value = 2; };
size_t nTest = tester<wchar_t>::value;
在我的編譯器,wchar_t
被typedef爲unsigned short
。爲什麼在底層類型具有專業化時使用默認模板?
編輯:好的,所以我錯了它是類型定義。 Intellisense向我展示了其他東西。雖然我的跨平臺和代理問題仍然存在。
這引起了一個曲線球,因爲我想根據它的尺寸使用wchar_t
。
另一個相關的問題。我如何以跨平臺的方式與wchar_t
一起工作?我知道它在窗口上是16位,而在其他地方它可以是32位。如果它被定義爲32位類型,是否意味着它沒有(如在編譯器中被強制)使用代理對?
會這樣的工作?
template < typename T, size_t N = sizeof(wchar_t) > struct remap;
template <> struct remap< wchar_t, 2 > { typedef unsigned short type; };
template <> struct remap< wchar_t, 4 > { typedef unsigned long type; };
也許你錯了,你的編譯器工作正常(所以'wchar_t'是一個獨立的類型,而不是typedef)?嘗試爲'wchar_t'添加一個專門化,看看它是否沒有被使用(它當然適用於我有用的編譯器)。 –
你究竟在做什麼? – juanchopanza
@JerryCoffin'wchar_t'的專門化已經被使用,但在給定的例子中,它沒有被使用。我也試過類型定義我自己的類型,他們都工作,但wchar_t不。我如何檢查它是否是獨立類型?並會影響跨平臺的使用? – Twifty