Thread: Array Class GONE WILD!!!

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    Array Class GONE WILD!!!

    Every time I try to set one array class type to another, I get an illigal operation. WHY!!!!!????????
    Code:
    template <class T>
    class array
    {
    public:
    	array(int input_size)
    	{
    		Data = new T[input_size];
    		for(int x = 0; x < size; x++)
    			Data[x] = 0x0;
    		size = input_size;
    	
    	}
    
    	~array()
    	{
    		delete [] Data;
    	}
    
    	T* Data;
    
    	T &operator [] (int index)
    	{
    		return Data[index];
    	}
    
    	int operator = (array other)
    	{
    		for(int x = 0; x < size; x++)
    			Data[x] = other[x];
    		return 1;
    	}
    
    private:
    	int size;
    	
    };
    The other "array" I'm equating it to is of the same type (int). So what's going on?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Look here
    Code:
    	array(int input_size)
    	{
    		Data = new T[input_size];
    		for(int x = 0; x < size; x++)
    			Data[x] = 0x0;
    		size = input_size;
    	
    	}
    You set size after the for-loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  3. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  4. Replies: 4
    Last Post: 09-12-2001, 02:05 PM