Polymorphic templated method

This is a discussion on Polymorphic templated method within the C++ Programming forums, part of the General Programming Boards category; I am making some simple objects for file I/O. I want one of the member functions to be templated, but ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    126

    Polymorphic templated method

    I am making some simple objects for file I/O. I want one of the member functions to be templated, but I also want it to be a pure virtual method, because the interface is defined in an abstract base class. Does anyone know how to do this? Thanks.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,643
    Code:
    class Base
    {
    public:
        template<class T> virtual void foo(T a) = 0;
    };
    error C2898: 'void __thiscall Base::foo(T)' : member function templates cannot be virtual

    Looks like you are stuck with:
    Code:
    template <class T>
    class Base
    {
    public:
        virtual void foo(T a) = 0;
    };
    gg

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    yeah, that's what I figured...just thought I'd check though. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  2. inline templated class method as standalone function in namespace
    By monikersupreme in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2008, 11:38 AM
  3. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM
  4. Static templated method problem
    By mikahell in forum C++ Programming
    Replies: 6
    Last Post: 11-19-2006, 08:19 AM
  5. Replies: 3
    Last Post: 10-31-2005, 11:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21