Problem with template

L

lhommedumatch

Hi,
I have a derived template class and I want to call a method of the
derived class from the base class.
But the method need a template parameter.
How can I do?

Here is the code that doesn't work.

#include <iostream>
#include <string>

using namespace std;

//==============================================================
class A
{
public:
A()
{
std::cout << "constructeur de A" << std::endl;
}
~A()
{
std::cout << "destructeur de A" << std::endl;
}
};

//==============================================================
template <class T> class B: public A
{
public:
B():A()
{
std::cout << "constructeur de B" << std::endl;
}
~B()
{
std::cout << "destructeur de B" << std::endl;
}
T _value;
void setValue(T p_value)
{
_value = p_value;
}
};


//==============================================================
int main()
{
A *a = new B<int>;
a->setValue(23131);
delete a;
}
//==============================================================

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top