1,105,594 Community Members

error C2955: use of class template requires template argument list in C++/MFC

Member Avatar
mfcdoubt
Newbie Poster
3 posts since Oct 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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 ..

Member Avatar
Tom Gunn
Practically a Master Poster
681 posts since Jun 2009
Reputation Points: 1,164 [?]
Q&As Helped to Solve: 138 [?]
Skill Endorsements: 11 [?]
 
0
 
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> ?

Member Avatar
mfcdoubt
Newbie Poster
3 posts since Oct 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Tom Gunn
Practically a Master Poster
681 posts since Jun 2009
Reputation Points: 1,164 [?]
Q&As Helped to Solve: 138 [?]
Skill Endorsements: 11 [?]
 
0
 

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.

Member Avatar
mfcdoubt
Newbie Poster
3 posts since Oct 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
huda_7978
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
#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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article