मैं अनिश्चित अगर यह बजना 3.2 में एक बग या सी ++ 03 का उल्लंघन है, लेकिन ऐसा लगता है कि टेम्पलेट कक्षाओं के लिए टेम्प्लेट निर्माताओं की स्पष्ट इन्स्टेन्शियशन विफल रहता है, लेकिन टेम्प्लेटेड की स्पष्ट इन्स्टेन्शियशन टेम्पलेट कक्षाओं के सदस्य कार्य सफल होते हैं।स्पष्ट इन्स्टेन्शियशन
उदाहरण के लिए, के साथ एक समस्या के बिना निम्नलिखित compiles दोनों बजना ++ और जी ++:
template<typename T>
class Foo
{
public:
template<typename S>
void Bar(const Foo<S>& foo)
{ }
};
template class Foo<int>;
template class Foo<float>;
template void Foo<int>::Bar(const Foo<int>& foo);
template void Foo<int>::Bar(const Foo<float>& foo);
template void Foo<float>::Bar(const Foo<int>& foo);
template void Foo<float>::Bar(const Foo<float>& foo);
जबकि जी के साथ ++ बिना किसी चेतावनी के निम्नलिखित compiles लेकिन ++ बजना के साथ विफल:
template<typename T>
class Foo
{
public:
template<typename S>
Foo(const Foo<S>& foo)
{ }
};
template class Foo<int>;
template class Foo<float>;
template Foo<int>::Foo(const Foo<int>& foo);
template Foo<int>::Foo(const Foo<float>& foo);
template Foo<float>::Foo(const Foo<int>& foo);
template Foo<float>::Foo(const Foo<float>& foo);
विशेष रूप से, मैं फॉर्म के दो त्रुटि संदेश देखें:
TemplateMember.cpp:12:20: error: explicit instantiation refers to member
function 'Foo<int>::Foo' that is not an instantiation
template Foo<int>::Foo(const Foo<int>& foo);
^
TemplateMember.cpp:9:16: note: explicit instantiation refers here
template class Foo<int>;
^
क्या यह उल्लंघन है मानक + या clang ++ में एक बग का?
वैध सी ++ 03 की तरह लग रहा। शायद क्लेंग ++ –