हम follwing स्रोत कोड के संकलन में एक अजीब व्यवहार देखा है:सी ++ 11 टेम्पलेट उपनाम टेम्पलेट टेम्पलेट तर्क के रूप में विभिन्न प्रकार की ओर जाता है?
template<template<class> class TT> struct X { };
template<class> struct Y { };
template<class T> using Z = Y<T>;
int main() {
X<Y> y;
X<Z> z;
z = y; // it fails here
}
यह एक थोड़ा संशोधित C++ टेम्पलेट अन्य नामों के लिए 11 मानक प्रस्ताव से लिया उदाहरण है: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf (पेज 4 देखें) यह भी ध्यान रखें कि प्रस्ताव "वाई और जेड को उसी प्रकार के होने की घोषणा करता है।" हमारी व्याख्या में इसलिए वाई से ज़ेड (या प्रतिलिपि बनाना) ज़ेड करना संभव होना चाहिए।
हालांकि, यह कोड जीसीसी 4.8.1 के साथ संकलित नहीं है और न ही क्लैंग 3.3 के साथ। क्या यह संकलक में एक त्रुटि है या क्या हमने मानक को गलत समझा है?)
पी.एस.;
अग्रिम, craffael एट अल में धन्यवाद बजना त्रुटि संदेश है:
error: no viable overloaded '='
note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'X<template Y>' to 'const X<template Z>' for 1st argument
template<template<class> class TT> struct X { };
note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'X<template Y>' to 'X<template Z>' for 1st argument
template<template<class> class TT> struct X { };
'वाई' और 'जेड' अलग-अलग * टेम्पलेट-नाम * हैं, क्योंकि वे 'एक्स' के साथ अलग-अलग तत्कालताएं उत्पन्न करते हैं। §14.5.7/1 देखें। – Xeo