मैंने केवल CRTP के बारे में विकी आलेख पढ़ा है, और मैं टेम्पलेट त्वरण के बारे में थोड़ा उलझन में हूं।कक्षा टेम्पलेट तत्काल
विकि के अनुसार,
सदस्य समारोह निकायों (परिभाषाओं) लंबे उनकी घोषणाओं के बाद जब तक instantiated नहीं कर रहे हैं।
मुझे समझ में नहीं आता कि इसका क्या अर्थ है।
मान लीजिए मैं एक वर्ग टेम्पलेट मिल गया:
template <typename T>
class A
{
public:
void foo(T t)
{
//...
};
};
जब मैं कक्षा टेम्पलेट एक दृष्टांत है, यह सदस्य समारोह foo का दृष्टांत है()?
उदाहरण के लिए:
प्रारंभ होता है संकलन दौरान, नहीं रनटाइम के दौरान:
//in .cpp file
int main()
{
A<int> a; //question 1
//class template is instantiated here, isn't it?
//What about foo(), is it instantiated too?
a.foo(10); //question 2
//according to the quotation, foo() will not be instantiated until it is used.
//if so, foo() is instantiated right here, not in question 1, right?
}
प्लग: यह आपके सवालों के जवाब हो सकता है: http: // stackoverflow।कॉम/प्रश्न/718235 9/टेम्पलेट-तत्काल-विवरण-के-जीसीसी-एंड-एमएस-कंपाइलर्स/7241548 # 7241548 –