मैं टेम्पलेट्स के निम्नलिखित सेट हैटेम्पलेट्स विशेषज्ञता
//1
template< typename T > void funcT(T arg)
{
std::cout<<"1: template< typename T > void funcT(T arg)";
}
//2
template< typename T > void funcT(T * arg)
{
std::cout<<"2: template< typename T > void funcT(T * arg)";
}
//3
template<> void funcT<int>(int arg)
{
std::cout<<"3: template<> void funcT<int>(int arg)";
}
//4
template<> void funcT< int * >(int * arg)
{
std::cout<<"4: template<> void funcT< int *>(int * arg)";
}
//...
int x1 = 10;
funcT(x1);
funcT(&x1);
किसी कृपया समझा क्यों funcT(x1);
कॉल # 3 समारोह और funcT(&x1);
कॉल समारोह # 2 लेकिन अपेक्षा के अनुरूप नहीं # 4?
मैंने पहले ही इस आलेख को http://www.gotw.ca/publications/mill17.htm पढ़ा है जो कहता है कि "ओवरलोड रिज़ॉल्यूशन विशेषज्ञता को अनदेखा करता है और केवल बेस फ़ंक्शन टेम्पलेट्स पर काम करता है"। लेकिन इस तर्क के अनुसार funcT(x1);
फ़ंक्शन # 1 को कॉल करना चाहिए, न कि # 3। मैं उलझन में हूं।
यह प्रासंगिक प्रतीत होता है: http://www.gotw.ca/publications/mill17.htm –
मैं आपको इसके लिए वास्तव में एक पुस्तक भेज सकता हूं: एडिसन वेस्ले - सी ++ टेम्पलेट्स - पूर्ण मार्गदर्शिका – erick2red