template and dynamic polymorphism

J

Jun

struct Abstract{

virtual void run() const = 0;

};

template <typename T>
struct S : F{
void run(){}
};


I just want to use as :

Abstract* a = new S<policy_1>(); // doesn't work


I just wanna to know how i could mix the templates with the
traditional abstract class design, thank you in advance.
 
J

Jun

* Jun:








How about deriving S from Abstract.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Sorry, my code is actually :

struct S : Abstract // and still doesn't work
 
L

Leandro Melo

Sorry, the code is :

You get the error because you're hidding run() from class abstract (in
S you're not making the function const). Try this:
template <typename T>
struct S : Abstract
{
void run()const {} //Notice the const at the end.
};
 
R

Rolf Magnus

Alf said:
* Jun:

How about deriving S from Abstract.

Another thing that comes to mind would be to make run() in S const, like in
Abstract, as well as telling, what "doesn't work" exactly means in this
case.
 
J

Jun

Another thing that comes to mind would be to make run() in S const, like in
Abstract, as well as telling, what "doesn't work" exactly means in this
case.

Thanks a lot, after changing the run as const in S, it works fine.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top