जब यह कोड मैं निम्नलिखित error संकलन:गैर-कॉन्स्टेंस संदर्भ का अमान्य प्रारंभिक अर्थ क्या है?
In function 'int main()': Line 11: error: invalid initialization of non-const reference of type 'Main&' from a temporary of type 'Main'
यहाँ मेरी कोड है:
template <class T>
struct Main
{
static Main tempFunction(){
return Main();
}
};
int main()
{
Main<int> &mainReference = Main<int>::tempFunction(); // <- line 11
}
मैं क्यों समझ में नहीं आता? क्या कोई समझा सकता है?
क्या त्रुटि – Mark
है कृपया संकलक से सटीक त्रुटि संदेश पोस्ट। –
आपकी टेम्पलेट घोषणा पैरामीटर श्रेणी पर निर्भर नहीं है। –