मैं समझने की कोशिश कर रहा हूं कि हम कक्षा-सदस्य-पहुंच अभिव्यक्ति के माध्यम से नेस्टेड प्रकार का उपयोग क्यों नहीं कर सकते हैं।हम कक्षा-सदस्य-पहुंच अभिव्यक्ति के माध्यम से नेस्टेड प्रकार का उपयोग क्यों नहीं कर सकते?
struct U
{
struct A
{
static int v;
int a;
};
struct B
{
int b;
};
};
U a;
typedef a.A T; //'a' does not name a type
int main()
{
std::cout << typeid(a.A).hash_code(); //invalid use of 'struct U::A'
struct a.A b; //trying to declare a variable of type U::A
//error: expected unqualified-id before '.' token
a.A b; //the same as above
//error: expected unqualified-id before '.' token
a.A.v = 5; //error: expected unqualified-id before '.' token
}
स्टैंडर्ड का कहना है:: उदाहरण के लिए, हम निम्नलिखित वर्ग है
धारा N3797::5.2.5/2 [expr.ref]
For the first option (dot) the first expression shall have complete class type. For the second option (arrow) the first expression shall have pointer to complete class type. The expression E1->E2 is converted to the equivalent form (*(E1)).E2; the remainder of 5.2.5 will address only the first option (dot).In either case, the id-expression shall name a member of the class or of one of its base classes.
जबकि, खंड N3797::9.2/1 [class.mem]
वर्ग के एक परिभाषा देता है सदस्य:
Members of a class are data members, member functions (9.3), nested types, and enumerators.
तो मुझे नेस्टेड प्रकार के उपयोग के लिए प्रतिबंध नहीं दिख रहा है। क्यों नहीं?
यह एक खंड है "* यदि ई 2 को टाइप करने के लिए घोषित किया गया है" टी के संदर्भ में, "*", मुझे नहीं लगता कि यह यहां लागू होता है। – luk32
@ luk32 "यदि ई 2 को" टी के संदर्भ "के रूप में घोषित किया गया है, तो E1.E2 एक अंतराल है; E1.E2 का प्रकार टी है। ** अन्यथा, निम्न नियमों में से एक लागू होता है। **" – user657267
ओह मैं इसे उलट गया। मैंने इसे 3 बार पढ़ा था कि यह टी का संदर्भ होना था। हालांकि मैं जवाब में अधिक संदर्भ डालूंगा। मुझे लगता है कि एक पूरा नियम होना महत्वपूर्ण है। आईएमओ यह है। – luk32