abstract class & template methods

  • Thread starter Manuel Maria Diaz Gomez
  • Start date
M

Manuel Maria Diaz Gomez

Hi Everybody

I would like to implement an interface class (abstract), where the pure
virtual method can take any parameter, and leave the actual implementation
to the end user.

I believe this is not correct:

template<typename T>
class IBase {

public:
virtual void do_something(T) = 0;

};

Any hints?

Cheers
Manuel

--
========================================================================
Manuel Diaz-Gomez | ATLAS Bldg. 32/SB-008 tel. +41 22 76 76304
CERN EP Division
CH-1211 Geneva 23
SWITZERLAND
========================================================================
 
V

Victor Bazarov

Manuel Maria Diaz Gomez said:
I would like to implement an interface class (abstract), where the pure
virtual method can take any parameter, and leave the actual implementation
to the end user.

I believe this is not correct:

template<typename T>
class IBase {

public:
virtual void do_something(T) = 0;

};

Any hints?

What hints? Why do you say it's not correct?
----------------------------------- compiles fine:
template<typename T>
class IBase {
public:
virtual void do_something(T) = 0;
};

class D : public IBase<int> {
virtual void do_something(int);
};

int main() {
D d;
IBase<int>& rib = d;
rib.do_something(42);
}
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top