mike.h on Mon, 17 Feb 2003 18:52:08 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] C++: deriving from templated classes


Jeff,

Perhaps this will help:

#include <iostream>
using namespace std;

template <class footype, class bartype>
class mypair{
        public:
                footype afoo;
                bartype abar;
                mypair(footype f, bartype b) : afoo(f), abar(b){}
};

template <class footype, class bartype>
class myderived : public mypair<footype, bartype>{
        public:
                myderived(footype f, bartype b) : mypair<footype,
bartype>(f, b){}
};

int main(){
        mypair<int, int> p (1,2);
        cout << p.afoo << "\n" << p.abar << "\n";
        myderived<int,int> d (3,4);
        cout << d.afoo << "\n" << d.abar << "\n";

        return 0;
}

On Sun, 2003-02-16 at 19:17, Jeff Abrahamson wrote:
> Looking for more syntax help, I've gotta get a copy of version 3 of
> Stroustrup soon.
> 
> I'm trying to derive from a templated class, but I'm not getting the
> syntax right. The C++ faq and google aren't helping me here. Pointers
> or outright answers appreciated.
> 
> Thanks much. Here's the simple example:
> 
> 
>     template <class T>
>     class SwapArray {
> 
>     };
> 
> 
>     class Bar : public template <class T> SwapArray {
>     //class Bar : public SwapArray {
> 
>     };
> 
> 
> -- 
>  Jeff
> 
>  Jeff Abrahamson  <http://www.purple.com/jeff/>
>  GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B
-- 
-mike.h
_________________
mike.h@acm.org
mike.h@stemik.com
__________________________________________
Democracy is the worst form of government; 
except for all those other forms that have 
been tried from time to time.

-Winston Churchill


Attachment: signature.asc
Description: This is a digitally signed message part