Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Anyone explain me this thing .. I'l b thankful .. [modified]

Anyone explain me this thing .. I'l b thankful .. [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pimra
    wrote on last edited by
    #1

    template < class type > class binarytree { public: struct treenode { int element; treenode *left, *right; treenode() : left(0), right(0) {} treenode(int item, treenode *leftnode=0, treenode *rightnode=0):element(item), left(leftnode), right(rightnode){} }; protected: treenode *root; BOOL insert(treenode *&tree, const type& item); .... }; template < class type > BOOL binarytree::insert(treenode* &tree, const type& item) { if ( tree==0 ) { tree=new treenode(item); return tree ? TRUE : FALSE; } else if (item < tree->element ) return insert(tree->left, item); else return insert (tree->right, item); } :confused: what is thing "BOOL" in this code ?? how can a function return TRUE, FALSE or a node of type treenode at same time. If anyone can clear me this thing BOOL, FALSE, TRUE .. I'l b thankful ... -- modified at 13:18 Thursday 7th December, 2006

    D D 2 Replies Last reply
    0
    • P Pimra

      template < class type > class binarytree { public: struct treenode { int element; treenode *left, *right; treenode() : left(0), right(0) {} treenode(int item, treenode *leftnode=0, treenode *rightnode=0):element(item), left(leftnode), right(rightnode){} }; protected: treenode *root; BOOL insert(treenode *&tree, const type& item); .... }; template < class type > BOOL binarytree::insert(treenode* &tree, const type& item) { if ( tree==0 ) { tree=new treenode(item); return tree ? TRUE : FALSE; } else if (item < tree->element ) return insert(tree->left, item); else return insert (tree->right, item); } :confused: what is thing "BOOL" in this code ?? how can a function return TRUE, FALSE or a node of type treenode at same time. If anyone can clear me this thing BOOL, FALSE, TRUE .. I'l b thankful ... -- modified at 13:18 Thursday 7th December, 2006

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Pimra wrote:

      what is thing "BOOL" in this code ??

      It's the type that's returned from the insert() method. It usually evaluates to 0 and 1.

      Pimra wrote:

      how can a function return...a node of type treenode at same time.

      It's not.


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      P 1 Reply Last reply
      0
      • D David Crow

        Pimra wrote:

        what is thing "BOOL" in this code ??

        It's the type that's returned from the insert() method. It usually evaluates to 0 and 1.

        Pimra wrote:

        how can a function return...a node of type treenode at same time.

        It's not.


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        P Offline
        P Offline
        Pimra
        wrote on last edited by
        #3

        But when i write this code in my compiler that is microsft visual C++ 6.0 it gives error of undeclared identifier .. true=1, false=0 but this is in caps .. TRUE and FALSE also tht data type is bool not BOOL .. this caps thing gives eror and if replaced by smalls it gives eror for return types .. i simply cant understand this code .. Sir, if u plz take out little time from ur precious time and try 2 explain a little more , I'l b vry thankful ..

        M D 2 Replies Last reply
        0
        • P Pimra

          But when i write this code in my compiler that is microsft visual C++ 6.0 it gives error of undeclared identifier .. true=1, false=0 but this is in caps .. TRUE and FALSE also tht data type is bool not BOOL .. this caps thing gives eror and if replaced by smalls it gives eror for return types .. i simply cant understand this code .. Sir, if u plz take out little time from ur precious time and try 2 explain a little more , I'l b vry thankful ..

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          the BOOL type is either TRUE or FALSE and the bool type is either true or false


          Maximilien Lincourt Your Head A Splode - Strong Bad

          1 Reply Last reply
          0
          • P Pimra

            But when i write this code in my compiler that is microsft visual C++ 6.0 it gives error of undeclared identifier .. true=1, false=0 but this is in caps .. TRUE and FALSE also tht data type is bool not BOOL .. this caps thing gives eror and if replaced by smalls it gives eror for return types .. i simply cant understand this code .. Sir, if u plz take out little time from ur precious time and try 2 explain a little more , I'l b vry thankful ..

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Pimra wrote:

            true=1, false=0

            true and false are already defined.

            Pimra wrote:

            ...this caps thing gives eror...

            Because TRUE and FALSE have not been defined.


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            1 Reply Last reply
            0
            • P Pimra

              template < class type > class binarytree { public: struct treenode { int element; treenode *left, *right; treenode() : left(0), right(0) {} treenode(int item, treenode *leftnode=0, treenode *rightnode=0):element(item), left(leftnode), right(rightnode){} }; protected: treenode *root; BOOL insert(treenode *&tree, const type& item); .... }; template < class type > BOOL binarytree::insert(treenode* &tree, const type& item) { if ( tree==0 ) { tree=new treenode(item); return tree ? TRUE : FALSE; } else if (item < tree->element ) return insert(tree->left, item); else return insert (tree->right, item); } :confused: what is thing "BOOL" in this code ?? how can a function return TRUE, FALSE or a node of type treenode at same time. If anyone can clear me this thing BOOL, FALSE, TRUE .. I'l b thankful ... -- modified at 13:18 Thursday 7th December, 2006

              D Offline
              D Offline
              Dan McCormick
              wrote on last edited by
              #6

              1. Sounds like the conditional expression syntax is confusing you.

              return tree ? TRUE : FALSE;

              is equivalent to

              if (tree != NULL)
              return TRUE;
              else
              return FALSE;

              2. A long time ago, in a time now forgotten, the data type bool and it's associated constants of true and false had not been created. Microsoft wanted a boolean type for use in their Windows code, so they created one and named it 'BOOL'. It was created using a typedef statement. BOOL has associated constants of TRUE and FALSE that are defined using the C-Preprocessor macro facility (in other words, #define). Much code was written using BOOL, TRUE and FALSE. Some time later, the ANSI committee got around to adding bool to the language as a native type (that is exactly one byte in size). Alas, the Windows code base, which used BOOL, was now quite large. It was a bigger pain to change to use bool than not to change, so BOOL was kept. So we have the legacy in Windows C++ code of seeing both BOOL and bool used. In order for BOOL to work, the proper headers must be included in the file. The definitions live in <WinDef.h> but if you just include <windows.h> ( or "stdafx.h" if you are using MFC ) before the template definition, the template code will have these values defined. Dan

              Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer's software. ----- Boris Beizer

              Steve EcholsS 1 Reply Last reply
              0
              • D Dan McCormick

                1. Sounds like the conditional expression syntax is confusing you.

                return tree ? TRUE : FALSE;

                is equivalent to

                if (tree != NULL)
                return TRUE;
                else
                return FALSE;

                2. A long time ago, in a time now forgotten, the data type bool and it's associated constants of true and false had not been created. Microsoft wanted a boolean type for use in their Windows code, so they created one and named it 'BOOL'. It was created using a typedef statement. BOOL has associated constants of TRUE and FALSE that are defined using the C-Preprocessor macro facility (in other words, #define). Much code was written using BOOL, TRUE and FALSE. Some time later, the ANSI committee got around to adding bool to the language as a native type (that is exactly one byte in size). Alas, the Windows code base, which used BOOL, was now quite large. It was a bigger pain to change to use bool than not to change, so BOOL was kept. So we have the legacy in Windows C++ code of seeing both BOOL and bool used. In order for BOOL to work, the proper headers must be included in the file. The definitions live in <WinDef.h> but if you just include <windows.h> ( or "stdafx.h" if you are using MFC ) before the template definition, the template code will have these values defined. Dan

                Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer's software. ----- Boris Beizer

                Steve EcholsS Offline
                Steve EcholsS Offline
                Steve Echols
                wrote on last edited by
                #7

                Gave you a 5 for the "tale of the BOOL". :)


                - S 50 cups of coffee and you know it's on!

                • S
                  50 cups of coffee and you know it's on!
                  Code, follow, or get out of the way.
                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups