Thread: problem with classes

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    5

    problem with classes

    i am new to this forum as i'm sure you can tell. i am having a problem with this class i wrote. i am geting this error:error C2601: 'add' : local function definitions are illegal. for each of the functions in my class that have to have an int to work.
    Code:
    //Declarations
    
    class Narray
    {
    private:
        int i;
    	int numels;
    
    public:
        struct arraydef
    	{
    		int el[10];
    	};
    
    	struct arraydef marray;
    	Narray();
                    int orig();
                    int full();
    	int empty();
    	int add(int);            //i get an error here
    	int remove(int);      //and here
                    int query(int);        //and here also
                                                 //as well as in the main
    };
    i'll just post one of the funtions and hopefully all the problems are the same.

    Code:
    int Narray::add(int num)
    {
        if(full())
    	{
    		return -1;
    	}
    	for(i = 0; i < 10; i++)
    	{
    		if(marray.el[i] == -1)
    		{
    			marray.el[i] = num;
    			numels = numels + 1;
                break;
    		}
    	}
       return 0;
    }
    thanks for any help....

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > i am geting this error:error C2601: 'add' : local function definitions are illegal.
    Look for a missing closing brace in the previous function.
    Code:
    void foo ( void ) {
    } // if this is missing, the compiler sees you trying to define bar, before you've finished foo
    // in other words, it looks like a nested function.
    void bar ( void ) {
    }

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    5
    wow man thanks a lot. that was the exact problem.

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, 07:40 PM
  4. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 12:30 PM
  5. problem w/ nested templatized classes
    By *ClownPimp* in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2002, 07:58 AM