संभव डुप्लिकेट:
Forward declaration of nested types/classes in C++मैं एक आंतरिक कक्षा घोषित कैसे करूं?
मैं बहुत की तरह एक वर्ग कहीं और है ...
class Container {
public:
class Iterator {
...
};
...
};
, मैं संदर्भ द्वारा एक कंटेनर :: इटरेटर पास करना चाहते हैं, लेकिन मैं हेडर फ़ाइल शामिल नहीं करना चाहता हूं। अगर मैं कक्षा घोषित करने की कोशिश करता हूं, तो मुझे संकलन त्रुटियां मिलती हैं।
class Container::Iterator;
class Foo {
void Read(Container::Iterator& it);
};
संकलन ऊपर कोड देता है ...
test.h:3: error: ‘Iterator’ in class ‘Container’ does not name a type
test.h:5: error: variable or field ‘Foo’ declared void
test.h:5: error: incomplete type ‘Container’ used in nested name specifier
test.h:5: error: ‘it’ was not declared in this scope
कैसे मैं आगे इस वर्ग घोषणा कर सकते हैं तो मैं हेडर फाइल कि इटरेटर वर्ग वाणी शामिल करने के लिए नहीं है?
आम आधार वर्ग सबसे अधिक मेरे अंत में उपयोग किया जाने वाला समाधान है। – Coyote
यदि आप चाहें तो आप इसके आसपास काम करने के लिए मित्र का उपयोग कर सकते हैं। –
यह गलत है: http: //en.cppreference।com/डब्ल्यू/सीपीपी/भाषा/nested_types – Nikerboker