boolean klasse



  • ich suche eine gute boolean klasse.

    mfg



  • struct boolean {bool b;};
    

    😉



  • lol der fragt nach ner klasse und du gibst ihm ein struct. 👎



  • 123 schrieb:

    lol der fragt nach ner klasse und du gibst ihm ein struct. 👎

    Ein struct ist eine Klasse..



  • Ansichtssache



  • ceplusplus@loggedoff schrieb:

    Ansichtssache

    Hmm. Nö.

    ISO/IEC 14882 9/4 schrieb:

    4 A structure is a class defined with the class-key struct; its members and base classes (clause 10) are public
    by default (clause 11).



  • 123 schrieb:

    lol der fragt nach ner klasse und du gibst ihm ein struct. 👎

    class boolean{ public: bool b; };
    

    zufrieden?



  • zwutz schrieb:

    123 schrieb:

    lol der fragt nach ner klasse und du gibst ihm ein struct. 👎

    class boolean{ public: bool b; };
    

    zufrieden?

    jetzt fehlen der klasse nur noch ein paar mett hoden



  • meine fresse:

    class CBoolean
    { 
    private: 
        bool m_bool; 
    
    public:
        bool GetBool() { return m_bool; }
        void SetBool(bool b) { m_bool = bool; }
    };
    


  • wenn es so weitergeht, haben wir hier bald ein Boolean-Framework stehen ^^



  • zwutz schrieb:

    wenn es so weitergeht, haben wir hier bald ein Boolean-Framework stehen ^^

    wär doch mal was 😃 ich mach mal weiter:

    class CBoolean 
    { 
    private: 
        bool m_bool; 
    
    public: 
        bool GetBool() { return m_bool; } 
        void SetBool(bool b) { m_bool = bool; }
    
        void ToggleBool() { m_bool = !m_bool; } 
    };
    

    😃



  • namespace useless_and_unsafe_wrappers_for_builtin_datatypes {
    
       class Boolean {
       public:
          Boolean( bool value ) : m_value( value ) {}
    
          operator unspecified-bool-type() const { return m_value; }
    
          Boolean operator!() { return Boolean( !m_value ); }
          Boolean& operator=( bool rhs ) { m_value = rhs; return *this; }
       };
    
    } // namespace useless_and_unsafe_wrappers_for_builtin_datatypes
    

    EDIT:
    Hier wäre doch jetzt auch ein binärer !-Operator toll 😃



  • namespace useless_and_unsafe_wrappers_for_builtin_datatypes 
    {
        class CBoolean 
        { 
        public: 
            CBoolean( bool value ) : m_value( value ) {} 
            ~CBoolean();
    
            operator unspecified-bool-type() const { return m_value; } 
    
            CBoolean operator!() { return Boolean( !m_value ); } 
            CBoolean& operator=( bool rhs ) { m_value = rhs; return *this; } 
        private:
            bool m_value;
        }; 
    
    } // namespace useless_and_unsafe_wrappers_for_builtin_datatypes
    

    Immer dieser Java-Slang :p



  • Da fehlten noch die wichtigsten Funktionen:

    namespace useless_and_unsafe_wrappers_for_builtin_datatypes {
    
       class Boolean {
       private:
        	bool m_value;
    
       public:
          Boolean( bool value ) : m_value( value ) {}
    
          operator unspecified-bool-type() const { return m_value; }
    
          Boolean operator!() { return Boolean( !m_value ); }
          Boolean& operator=( bool rhs ) { m_value = rhs; return *this; }
    
          bool IsTrue() {
          	return m_value == true;
          }
    
          bool IsNotTrue() {
          	return m_value != true;
          }
    
          bool IsFalse() {
          	return m_value == false;
          }
    
          bool IsNotFalse() {
          	return m_value != false;
          }
       };
    
    } // namespace useless_and_unsafe_wrappers_for_builtin_datatypes
    

    Eine Alternative wäre das hier



  • bool isTrue()
    {
        if(m_bool == true && m_bool != false)
        {
            return true;
        }
        else if(m_bool == false && m_bool != true)
        {
            return false;
        }
        else
        {
            assert(false);
        }
    }
    


  • Du hast vergessen, den Wertebereich auf Gültigkeit sowie die Funktionstüchtigkeit des Compilers zuvor zu überprüfen:

    assert(m_bool == true || m_bool == false);
    assert(m_bool && m_bool == true);
    assert(!m_bool && m_bool == false);
    


  • LordJaxom schrieb:

    Du hast vergessen, den Wertebereich auf Gültigkeit sowie die Funktionstüchtigkeit des Compilers zuvor zu überprüfen:

    assert(m_bool == true || m_bool == false);
    assert(m_bool && m_bool == true);
    assert(!m_bool && m_bool == false);
    

    Du wolltest du blos deine 4000 haben. 🙂

    Im übrigen hatten wir das alles bereits einmal (um genau zu sein 2 mal.) 😉

    Ich finde, dass die Rückgabewerte noch einen eigenen Datentypen bekommen. Das geht so ja wirklich nicht.



  • Und immer schön auf die const-correctness achten! 🙂

    namespace useless_and_unsafe_wrappers_for_builtin_datatypes {
    
       class Boolean {
       private:
            bool m_value;
    
       public:
          Boolean( bool value ) : m_value( value ) {}
    
          operator unspecified-bool-type() const { return m_value; }
    
          Boolean operator!() const { return Boolean( !m_value ); }
          Boolean& operator=( bool rhs ) { m_value = rhs; return *this; }
    
          bool IsTrue() const {
              return m_value == true;
          }
    
          bool IsNotTrue() const {
              return m_value != true;
          }
    
          bool IsFalse() const {
              return m_value == false;
          }
    
          bool IsNotFalse() const {
              return m_value != false;
          }
       };
    
    } // namespace useless_and_unsafe_wrappers_for_builtin_datatypes
    


  • Wo bleibt die synchronisierung?



  • spam1256 schrieb:

    Wo bleibt die synchronisierung?

    Muss doch garnichts synchronisiert werden. 🙂


Anmelden zum Antworten