निम्न उदाहरण लें:जी ++ - छाया टेम्पलेट मानकों के आधार पर 6 त्रुटियों जबकि जी ++ - 5 नहीं है
g++-6
के साथ संकलित करने के लिए विफल रहता है है:
#include <vector>
template <typename T, template <class T> class Container>
std::vector<T> To_Vector(Container<T> const& c){
return std::vector<T>(c.begin(), c.end());
}
int main(){}
g++-5
साथ
, यह त्रुटियों के बिना संकलित :
g++-6 -o main main.cpp
main.cpp:4:33: error: declaration of template parameter ‘T’ shadows template parameter
template <typename T, template <class T> class Container>
^~~~~
main.cpp:4:11: note: template parameter ‘T’ declared here
template <typename T, template <class T> class Container>
क्या संकलक गलत है? क्या मेरा कोड गलत है?
क्यों g++-5
इस कोड जबकि g++-6
नहीं है संकलित करता है?
g++-5 --version
g++-5 (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++-6 --version
g++-6 (Ubuntu 6.2.0-3ubuntu11~14.04) 6.2.0 20160901
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@skypjack ठीक है, तो मैं बाहर 'टी' में छोड़ देना चाहिए, क्योंकि सिर्फ मेरे लिए बनाता है। –
यह एक वैध और कामकाजी समाधान है। वह 'टी' आपके उदाहरण में बेकार है, है ना? – skypjack
@skypjack आप सही हैं। मैं यह सोच कर कि कंटेनर प्रकार का नाम पर प्रकार टी विशेष किया जा सकता था में भ्रमित करना चाहिए किया गया है, लेकिन यह है कि वास्तविक मानकों के आधार पर होता है। –