Facing problem in creating object of derived class (whish is derived from template class) and pushing object in list
- From: "Shilpa Uttarwar" <shilpa.uttarwar@xxxxxxxxxxxxx>
- Date: Mon, 18 Aug 2008 19:12:45 +0530
Hi,
My base class is template class as:
template<typename T>
class CheckTemp
{
T a;
public:
CheckTemp(){}
void display(T a);
};
Derived class as:
class TestDerive: CheckTemp<int>
{
int a;
public:
void Print();
};
I have to make container of TestDerive objects. Declared list as:
typedef std::list<CheckTemp<int>* > ptls;
Code in main() where error occurs is as below:
int main()
{
ptls pls;
CheckTemp<int> obj = new TestDerive();
pls.push_back(obj); //Error in this line
return 0;
}
Errors are:
Error 2 error C2664: 'std::list<_Ty>::push_back' : cannot convert parameter
1 from 'CheckTemp<T>' to 'CheckTemp<T> &'
d:\mqsamples\templatesample\testmain.cpp 35
Error 1 error C2440: 'initializing' : cannot convert from 'TestDerive *' to
'CheckTemp<T>' d:\mqsamples\templatesample\testmain.cpp 34
Also I want to know Is derived class is also a Template class?
What could be the reason for this problem?
Any pointers or help to resolve this problem is appreciable.
Thanks And Regards
Shilpa
.
- Follow-Ups:
- Prev by Date: Re: Cannot Use GUID in map
- Next by Date: Re: Facing problem in creating object of derived class (whish is derived from template class) and pushing object in list
- Previous by thread: Re: Cannot Use GUID in map
- Next by thread: Re: Facing problem in creating object of derived class (whish is derived from template class) and pushing object in list
- Index(es):
Relevant Pages
|