1
我想專業化類模板的構造函數。這不起作用:專業化的類模板構造函數
template<typename T>
struct One {};
template<typename T>
struct Two {};
template<template<typename> class T, template<typename> class U>
struct Three : public T<Three<T, U>>, public U<Three<T, U>> {};
template<typename T> struct Four;
template<typename T>
struct Four
{
Four();
};
template<template<typename> class T, template<typename> class U>
Four<Three<T, U>>::Four() {}
int main(int argc, char *argv[])
{
Four<Three<One, Two> > obj;
}
但改變類模板定義這部作品:
template<typename T> struct Four;
template<template<typename> class T, template<typename> class U>
struct Four<Three<T, U>>
{
Four();
};
template<template<typename> class T, template<typename> class U>
Four<Three<T, U>>::Four() {}
這似乎是我專門整個類模板。不過,我想只專注於上面的代碼中的構造函數 - 不起作用的構造函數。爲什麼我不能專門化Four
的構造函數只爲Three
(我不改變類模板的ctor的簽名)?
雅本會工作,所以確實'模板<>四<三> ::四( ){}'。但是什麼阻止了我做不起作用的那個。我不以任何方式更改構造函數,除非我這樣做,我不應該專門化整個類(如果我想'四(const std :: string&)'爲例我理解的專門案例)。那麼你能告訴我什麼樣的標準規則適用於這種情況嗎(以上述方式限制使用)? –
ustulation