Using bitset class inside another

This is a discussion on Using bitset class inside another within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I'm working on a Red-Black Binary Tree project that's using (or trying to) the standard bitset class. When ...

  1. #1
    Beeing Beat By Binaries
    Join Date
    Jul 2005
    Location
    Espírito santo/Brazil
    Posts
    6

    Question Using bitset class inside another

    Hi everyone,
    I'm working on a Red-Black Binary Tree project that's using (or trying to) the standard bitset class.

    When I try to declare a bitset inside a struct that belongs to the RBTree class (or anyother place in the class) i get this message from the compiler (I'm using Dev-C++, newest version, in Windows)
    ISO C++ forbids declaration of `bitset' with no type

    First I though it was some syntax error, but I ran a code where the bitset isn't inside a class and it worked.
    So I looked up for a sample that used bitset inside a class, and I got the same error message.
    (this is the sample code)

    Anyone knows if this is just a Dev-C++ thing or am I doing something wrong?


    My code:
    Code:
    #include <iostream>
    #include <exception>
    #include <bitset>
    
    #define cor 0
    #define corp 1
    #define Fdir 2
    #define Fesq 3
    #define Pdir 4
    #define Pesq 5
    #define folha 6
    #define root 7
    
    #ifndef _RBTree_
    #define _RBTree_ 1
    
    class TRBTreeError: public std::exception{
        public:
            TRBTreeError (char *msg){
                printf("[RBTreeError]: %s\n",msg);
            }
    };
    
    
    class TRBTree{
        enum TraversingDir {
            sdInOrder,
            sdPreOrder,
            sdPosOrder,
        };
        typedef struct node{
            void *Data;
            struct node *pRight, *pLeft, *pFather;
            bitset<8> Info;
        } RBNode;
        public:
            TRBTree(int(*fnComp)(void*, void*), void(*getLabel)(void*, char*));
            ~TRBTree();
    	TraversingDir getTraversingDir();
    	void setTraversingDir(TraversingDir value);
            void Insert(void *data);
            bool Delete(void *data);
            bool Destroy(void *data);
            void *Search(void *data);
            void Last();
            void First();
            void Prior();
            void Next();
            void *getCurrent();
            void DeleteAll();
            void DestroyAll();
            int getCount();
            bool GoToFather();
            bool GoToLeft();
            bool GoToRight();
            bool GoToRoot();
            bool Successor();
            bool Antecessor();
            void WriteGraphvizSource(FILE *f, bool blackwhite = true);
        private:
            void LeftRotate(RBNode *node);
            void RightRotate(RBNode *node);
            RBNode *pRoot, *pCurrent;
            int FCount;
            int (*pFnComp)(void*, void*);
            void (*pFnGetLabel)(void*, char*);
            TraversingDir FTraversingDir;
    };
    
    #endif

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    Bitset is of the namespace "std"

    Code:
    std::bitset<8> test;

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Try this:
    Code:
    #include <iostream>
    #include <bitset>
    
    using namespace std;
    
    class Blah
    {
    private:
    	typedef struct node
    	{
    		int n;
    		bitset<8> Info;
    	}RBNode;
    
    	RBNode rbn;
    	
    public:
    	Blah(int num) 
    	{
    		rbn.n = num;
    		bitset<8> temp(num);
    		rbn.Info = temp;
    	}
    	void show()
    	{
    		cout<<rbn.n<<endl;
    		cout<<rbn.Info<<endl;
    	}
    };
    
    int main()
    {
    	Blah b(10);
    	b.show();
    
    	return 0;
    }

  4. #4
    Beeing Beat By Binaries
    Join Date
    Jul 2005
    Location
    Espírito santo/Brazil
    Posts
    6
    Worked perfectly

    Thanks, really, a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 11-15-2008, 06:11 PM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  3. Replies: 8
    Last Post: 10-02-2005, 01:27 AM
  4. Declaring an instance of a class inside a class
    By nickodonnell in forum C++ Programming
    Replies: 4
    Last Post: 10-02-2005, 12:46 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21