I have following header file defines

test2.h ----------> header file

template<class T>
class temp2
{
public:
temp2();
virtual ~temp2();
};

test1.h ----------> header file

template<class T>
class temp1
{
public:
temp1(temp2<T> (temp2<T> *temp2ptr);
~temp1(temp2<T> ();

protected:
temp2<T> *tempptr;

};


test3.h -------------> header file
class test3
{
public:
test3();
virtual ~test3();

};


template<class T> temp1<T>::temp1(temp2<T> *temp2ptr)
{
tempptr = temp2ptr;
}

main.h ----------> header file

temp1 *maintemp1;
temp2<test3> maintemp2;

and in main.cpp -------> source file I am creating an object for this like given below

maintemp1 = new temp1(&maintemp2);

Now when I compile I am getting error

error C2955: 'temp1' : use of class template requires template argument list

can any body tell me what is the wrong with my code block ..

Dani AI

Generated

The compiler is telling you exactly what @Tom Gunn highlighted: when you name a class template, you must provide its argument list at every point of use where a concrete type is required. So both the pointer declaration and the allocation must spell the type as temp1<test3>, not just temp1. This is a language rule, not MFC-specific, and it is the canonical cause of MSVC error C2955. See Microsoft’s explanation and examples of the same fix. MSVC C2955 docs

A second common source of C2955 (which bites the snippet from ) is forgetting the template parameter list on an out-of-class member definition. The definition must repeat both the template<...> line and the qualified class name with <T>:

template<class T>
T mypair<T>::getmin() { /* ... */ }

MSVC’s C2955 page shows this exact pattern with a minimal failing example and the corrected form. MSVC C2955 docs

Practical tips you can apply right now:

  • Reduce repetition with a type alias so you do not miss an angle bracket later:
using T1 = temp1<test3>;
T1* maintemp1 = new T1(&maintemp2);
  • On modern C++17+ compilers, class template argument deduction (CTAD) can sometimes infer template arguments from constructor parameters when you construct by value (e.g., temp1 x(&maintemp2);). CTAD does not apply when you only name the template without constructing (such as in a pointer declaration), so you still need the <...> there. Class template argument deduction

Recommended Answers

All 5 Replies

temp1 *maintemp1;

temp1 is a template class. The error means exactly what it says, and you should add a template argument list. Maybe temp1<test3> ?

Hi,
Thank for your quick response, I changed my code block as you told

temp1<test3> maintemp1;
temp2<test3> maintemp2;

and in main.cpp -------> source file I am creating an object for this like given below

maintemp1 = new temp1(&maintemp2);

But still I am getting the same error as above

But still I am getting the same error as above

I am sorry, I should have been more specific. Change the name everywhere. Your compiler should be giving you line numbers in the error, so you can find where you need to make changes. In the code you posted, maintemp1 = new temp1(&maintemp2); will not work for the same reason. temp1 is a template and needs a list of template arguments:

maintemp1 = new temp1<test3>(&maintemp2);

Every time you use the name of a template, you need to provide a template argument list too.

Perfect It worked .. Thank you very much for your help

#include < iostream.h>
// class template
template < class T >
class mypair { private :
T a,b;
public:
    mypair(T first,T second){a= first; b=second;}
    T getmin();
};
template < class T >
T mypair::getmin(){ T retval;
retval=a<b?a:b;
return retval;}
void main(){
    mypair <int>myobject(100,75);
    cout<<myobject.getmin()<<endl;}

i don't now why i have this erorr :error C2955: 'mypair' : use of class template requires template argument list
please help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.