Error C 2955

This is a discussion on Error C 2955 within the C++ Programming forums, part of the General Programming Boards category; I'm trying to create a class template for arrays. The code mostly compiles ok except for the overloaded [] operator. ...

  1. #1
    Unregistered
    Guest

    Unhappy Error C 2955

    I'm trying to create a class template for arrays. The code mostly compiles ok except for the overloaded [] operator. This gives a C 2955 error in MSVC 6, but I don't understand why. The help file wasn't much help. Any ideas? Code below. Thanks.

    Header File
    Code:
    #include <iostream>
    using namespace std;
    
    template <class T>
    class t_Array  
    {
    public:
    	t_Array(int = 10);
    	virtual ~t_Array();
    	T &operator[](int);
    
    private:
    	T *ptr;
    	int size;
    };
    Implementation File
    Code:
    #include <iostream>
    #include <cassert>
    
    using namespace std;
    
    #include "t_Array.h"
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    template <class T>
    t_Array<T>::t_Array(int arraySize)
    {
    	size = (arraySize > 1 ? arraySize : 10);
    	ptr = new T[size];
    	assert(ptr != 0);
    }
    
    template <class T>
    t_Array<T>::~t_Array()
    {
    	delete [] ptr;
    }
    
    template <class T>
    T &t_Array::operator[](int subscript) // This is line 30 in error msg
    {
    	assert(1 <= subscript && subscript < size);
    	return ptr[subscript];
    }
    Error Message

    t_Array.cpp
    d:\documents and settings\cis-staff\desktop\greg\t_array\t_array.cpp(30) : error C2955: 't_Array' : use of class template requires template argument list
    d:\documents and settings\cis-staff\desktop\greg\t_array\t_array.h(26) : see declaration of 't_Array'

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    T &t_Array<T>::operator[](int subscript) // This is line 30 in error msg
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Unregistered
    Guest
    Thanks! Seems pretty simple, but I searched all over the web, including some Japanese or Chinese pages as well as microsoft, but no luck. Realy appreciate the help.

  4. #4
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133

    Error messages!

    To use the help with error messages double click the error in the build menu. Dont move the mouse or your cursor. Then press [F1] to acces the error.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Re: Error messages!

    Originally posted by ski6ski
    To use the help with error messages double click the error in the build menu. Dont move the mouse or your cursor. Then press [F1] to acces the error.
    Yeah, did that, but the explanation there wasn't very helpful. Thanks.

Popular pages Recent additions subscribe to a feed

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