Thread: templatized class inside templatized class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    templatized class inside templatized class

    what is wrong with the implementation of the add function for the vector class here?

    Code:
    namespace project {
    template <class _T>
    class type
    {
     public :
     	type();
     	type(int num);
    
     	type( const type & typ);
     	~type();
    
     protected :
     	_T val;
    
    };
    
    template <class type, size_t n>
    class vector
    {
      public:
    
      // constructors/destructor
        vector( );                        // default constructor (size==0)
       
        vector( const vector & vec );     // copy constructor
        ~vector( );                       // destructor
    
      // operator overloads
        const vector & operator = ( const vector<type, n>& vec );
    
      // add element to a vector
        void add(type value);
     
        vector<type, n>& operator+=(const vector<type, n>& vec);
        vector<type, n>& operator-=(const vector<type, n>& vec);
    
      // unary
        vector<type, n>& operator-();	
    	
      // member functions
        int  length( ) const;                  // capacity of vector
    
      //read access operator for a polynomial
        const type& operator[]( int index ) const;
    	
      //write access operator for a polynomial
        type& operator[]( int index );
    
     protected:    
        int csize;
        int  size;                             // # elements in array
        type * list;                          // array used for storage
        
    };
    
    template <class type, size_t n>
    void vector<type, n>::add(type value)
    {
     this.list[this.csize] = value;
     this.csize++;
    }
    }
    Last edited by -EquinoX-; 11-16-2009 at 09:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating an object of a class inside another class - possible?
    By Programmer_P in forum C++ Programming
    Replies: 34
    Last Post: 08-15-2009, 11:21 PM
  2. Replies: 2
    Last Post: 11-28-2008, 05:15 PM
  3. Unresolved external on vector inside class constructor
    By Mario F. in forum C++ Programming
    Replies: 13
    Last Post: 06-20-2006, 12:44 PM
  4. Declaring an instance of a class inside a class
    By nickodonnell in forum C++ Programming
    Replies: 4
    Last Post: 10-01-2005, 11:46 PM
  5. how do i define a const inside a class under private
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2001, 06:01 PM