वाह। सी ++ कभी भी मुझे अजीबता से आश्चर्यचकित नहीं करता है।
एक टेम्पलेट परिभाषा में, अयोग्य नाम अब एक निर्भर आधार के सदस्य नहीं पाएंगे (जैसा कि [temp.dep]/3 द्वारा निर्दिष्ट किया गया है C ++ मानक में)। उदाहरण के लिए,
template struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template struct C : B {
void h ()
{
m = 0;//error
f (); //error
n = 0;//::n is modified
g (); //::g is called
}
};
You must make the names dependent, e.g. by prefixing them with this->. Here is the corrected definition of C::h,
template void C::h ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
As an alternative solution (unfortunately not backwards compatible with GCC 3.3), you may use using declarations instead of this->:
template struct C : B {
using B::m;
using B::f;
using B::n;
using B::g;
void h ()
{
m = 0;
f ();
n = 0;
g ();
}
};
यह सिर्फ पागल के सभी प्रकार है। धन्यवाद, डेविड।
मानक [आईएसओ/आईईसी 14882: 2003] का "temp.dep/3" खंड यहां दिया गया है कि वे इसका जिक्र कर रहे हैं:
क्लास टेम्पलेट या क्लास टेम्पलेट के सदस्य की परिभाषा में, यदि क्लास टेम्पलेट का बेस क्लास टेम्पलेट-पैरामीटर पर निर्भर करता है, तो बेस क्लास स्कोप की परिभाषा के बिंदु पर अयोग्य नाम लुकअप के दौरान जांच नहीं की जाती है कक्षा टेम्पलेट या सदस्य या कक्षा टेम्पलेट या सदस्य के तत्काल के दौरान। [उदाहरण:
typedef double A;
template class B {
typedef int A;
};
template struct X : B {
A a;//a has typedouble
};
The type name A
in the definition of X
binds to the typedef name defined in the global namespace scope, not to the typedef name defined in the base class B
. ] [Example:
struct A {
struct B { /* ... */ };
int a;
int Y;
};
int a;
template struct Y : T {
struct B { /* ... */ };
B b; //The B defined in Y
void f(int i) { a = i; }//::a
Y* p;//Y
};
Y ya;
The members A::B
, A::a
, and A::Y
of the template argument A
do not affect the binding of names in Y
. ]