We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,642 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

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

3
Contributors
5
Replies
2 Years
Discussion Span
1 Year Ago
Last Updated
9
Views
mfcdoubt
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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> ?

Tom Gunn
Master Poster
733 posts since Jun 2009
Reputation Points: 1,446
Solved Threads: 135
Skill Endorsements: 8

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

mfcdoubt
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Tom Gunn
Master Poster
733 posts since Jun 2009
Reputation Points: 1,446
Solved Threads: 135
Skill Endorsements: 8

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

mfcdoubt
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

huda_7978
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0685 seconds using 2.69MB