जी ++ 4.2.1 का उपयोग कर इस कोड संकलन:त्रुटिपूर्ण निजी बेस क्लास पहुंच योग्य नहीं है?
struct S { };
template<typename T> struct ST { };
template<typename BaseType>
class ref_count : private BaseType { };
template<typename RefCountType>
class rep_base : public RefCountType { };
class wrap_rep : public rep_base<ref_count<S> > {
typedef rep_base<ref_count<S> > base_type; // line 11
};
मैं:
bug.cpp:1: error: ‘struct S’ is inaccessible
bug.cpp:11: error: within this context
हालांकि, अगर मैं ST
उपयोग करने के लिए wrap_rep
वर्ग बदलने के लिए:
class wrap_rep : public rep_base<ref_count< ST<int> > > {
typedef rep_base<ref_count< ST<int> > > base_type;
};
यह ठीक संकलित । वैकल्पिक रूप से, यदि मैं मूल कोड को बदलता हूं:
class wrap_rep : public rep_base<ref_count<S> > {
typedef rep_base<ref_count<::S> > base_type; // now using ::
};
यह भी ठीक संकलित करता है। मेरे लिए, मूल कोड ठीक जैसा लगता है। क्या यह एक जी ++ बग है? यदि नहीं, तो टेम्पलेट का उपयोग क्यों करते हैं? और, दूसरे मामले के लिए, ::S
क्यों आवश्यक है?
लेकिन फिर कोड टेम्पलेट बेस क्लास के साथ क्यों काम करता है? –