Könnte mir jemand erklären, warum dieser Code:Weird-Compiler-Fehler und Vorlage Vererbung
class safe_bool_base
{ //13
protected:
typedef void (safe_bool_base::*bool_type)() const;
void this_type_does_not_support_comparisons() const {} //18
safe_bool_base() {}
safe_bool_base(const safe_bool_base&) {}
safe_bool_base& operator=(const safe_bool_base&) { return *this; }
~safe_bool_base() {}
};
template <typename T=void> class safe_bool : public safe_bool_base
{
public:
operator bool_type() const
{
return (static_cast<const T*>(this))->boolean_test() ? &safe_bool_base::this_type_does_not_support_comparisons : 0;
}
protected:
~safe_bool() {}
};
template <> class safe_bool<void> : public safe_bool_base
{
public:
operator bool_type() const
{
return (boolean_test() == true) ? &safe_bool_base::this_type_does_not_support_comparisons : 0; //46
}
protected:
virtual bool boolean_test() const = 0;
virtual ~safe_bool() {}
};
Erzeugt den folgenden Compiler-Fehler?
c:\project\include\safe_bool.hpp(46) : error C2248: 'safe_bool_base::this_type_does_not_support_comparisons' : cannot access protected member declared in class 'safe_bool_base'
c:\project\include\safe_bool.hpp(18) : see declaration of 'safe_bool_base::this_type_does_not_support_comparisons'
c:\project\include\safe_bool.hpp(13) : see declaration of 'safe_bool_base'
Da beide safe_bool
Vorlagen aus safe_bool_base
ableiten, ich verstehe nicht, warum man nicht ein geschütztes Mitglied der Basisklasse zugreifen kann.
Fehle ich etwas?
Das ist eine gute Frage. Ich schlage vor, dass Sie das Tag 'protected', 'base', 'derived' auch der Frage hinzufügen, damit dies in Suchen/Referenzen auftaucht. – Chubsdad
@Chubsdad: Danke. Ich kann nur ein weiteres Tag hinzufügen. (5 ist die maximale Anzahl der Markierungen afaik.) – ereOn