Problem with classes

This is a discussion on Problem with classes within the C++ Programming forums, part of the General Programming Boards category; i have a class and it has these functions in it Code: void Modify(string member, int dat); void Modify(string member, ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    Problem with classes

    i have a class and it has these functions in it

    Code:
    void Modify(string member, int dat);
    void Modify(string member, BITMAP *bmp);
    int Access(string member);
    and i get these errors

    Code:
    5 C:\Temp\Adam\linkedlist\main.cpp In file included from main.cpp 
    19 C:\Temp\Adam\linkedlist\SpriteHandler.h variable or field `Modify' declared void 
    19 C:\Temp\Adam\linkedlist\SpriteHandler.h expected `;' before '(' token 
    20 C:\Temp\Adam\linkedlist\SpriteHandler.h variable or field `Modify' declared void 
    20 C:\Temp\Adam\linkedlist\SpriteHandler.h expected `;' before '(' token 
    21 C:\Temp\Adam\linkedlist\SpriteHandler.h expected `;' before '(' token
    the best i can come up with is the computer thinks that they are variables and not functions but i dont know how to change this

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Post your whole class.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    Code:
    //class for a sprite handler that uses linked list
    #ifndef SPRITEHANDLER_H
    #define SPRITEHANDLER_H
    
    #include <string>
    #include <allegro.h>
    #include <iostream>
    
    class SpriteHandler
    {
        public:
            SpriteHandler();
            ~SpriteHandler();
            
            int Length();
            bool Empty() const;
            bool AtEnd();
            
            void Modify(string member, int dat);
            void Modify(string member, BITMAP *bmp);
            int Access(string member);
            void First();
            void Next();
            void Insert(const int &dat);/*,const int x, const int y, const int ...*/
            void Update();
            void Bounce();
            void Move();
    
        private:
            struct node;
    		typedef node *node_ptr;
    		struct node
    		{
    		    BITMAP *sprite;
    			int data;
    			int x,y;
    			int width, height;
    			int xspeed, yspeed;
    			int xdelay, ydelay;
    			int xcount, ycount;
    			int curframe, maxframe, animdir;
    			int framecount, framedelay;
    			node *next;
    		};    
    		
    		node_ptr myFirst, myCurrent, myPrevious;
    		int Size;
    		
    		node_ptr GetNode(const int &dat);
    
    };    
    
    #endif

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    Code:
    //class for a sprite handler that uses linked list
    #ifndef SPRITEHANDLER_H
    #define SPRITEHANDLER_H
    
    #include <string>
    #include <allegro.h>
    #include <iostream>
    
    class SpriteHandler
    {
        public:
            SpriteHandler();
            ~SpriteHandler();
            
            int Length();
            bool Empty() const;
            bool AtEnd();
            
            void Modify(string member, int dat);
            void Modify(string member, BITMAP *bmp);
            int Access(string member);
            void First();
            void Next();
            void Insert(const int &dat);/*,const int x, const int y, const int ...*/
            void Update();
            void Bounce();
            void Move();
    
        private:
            struct node;
    		typedef node *node_ptr;
    		struct node
    		{
    		    BITMAP *sprite;
    			int data;
    			int x,y;
    			int width, height;
    			int xspeed, yspeed;
    			int xdelay, ydelay;
    			int xcount, ycount;
    			int curframe, maxframe, animdir;
    			int framecount, framedelay;
    			node *next;
    		};    
    		
    		node_ptr myFirst, myCurrent, myPrevious;
    		int Size;
    		
    		node_ptr GetNode(const int &dat);
    
    };    
    
    #endif
    if you want the functions too i can add them but i get the same errors when they are commented out and when they arrent

  5. #5
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    add the scope operator to string... std::string.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Just add:

    using namespace std;

    after any #includes in your files. The functions contained in the header files, as well as the string type that is defined in <string>, need to be qualified by their namespace name: std.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    i cant believe it is something that simple thanks alot though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with classes and pointers
    By Akkernight in forum C++ Programming
    Replies: 18
    Last Post: 02-21-2009, 06:21 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Having a problem with Classes
    By FoxTrot in forum C++ Programming
    Replies: 10
    Last Post: 09-06-2007, 08:40 PM
  4. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 01:30 PM
  5. problem w/ nested templatized classes
    By *ClownPimp* in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2002, 08:58 AM

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