アカウント名:
パスワード:
#include <string>#include <memory>#include "cls.h" int main(){ std::auto_ptr<Foo<int> > a(new Foo<int>(0)); a->hello(); std::auto_ptr<Foo<std::string> > b(new Bar<std::string>("str")); b->hello(); std::auto_ptr<Foo<char> > c(new Baz<char>('c')); c->hello(); return 0;}
#ifndef CLS_H#define CLS_H #include <iostream>#include <string> template <typename T>class Foo{public: Foo(T t) { t_ = t; } virtual ~Foo() { } virtual void hello(); protected: virtual T value(); private: Foo(); Foo(const Foo&); Foo& operator=(const Foo&); T t_;}; template <typename T>class Bar : public Foo<T> {public: Bar(T t) : Foo<T>(t) { } virtual ~Bar() { } virtual void hello(); private: Bar(); Bar(const Bar&); Bar& operator=(const Bar&);}; template <typename T>class Baz : public Foo<T>{public: Baz(T t) : Foo<T>(t) { } virtual ~Baz() { } virtual void hello(); private: Baz(); Baz(const Baz&); Baz& operator=(const Baz&);}; template <typename T>T Foo<T>::value(){ return t_;} template <typename T>void Foo<T>::hello(){ std::cout << "I am Foo. The value is " << this->value() << std::endl;} template <typename T>void Bar<T>::hello(){ std::cout << "I am Bar. The value is " << this->value() << std::endl;} template <typename T>void Baz<T>::hello(){ std::cout << "I am Baz. The value is " << this->value() << std::endl;} #endif// CLS_H
より多くのコメントがこの議論にあるかもしれませんが、JavaScriptが有効ではない環境を使用している場合、クラシックなコメントシステム(D1)に設定を変更する必要があります。
「毎々お世話になっております。仕様書を頂きたく。」「拝承」 -- ある会社の日常
クラステンプレートの継承? (スコア:0)
外しているかもしれないので AC 。
-- main.cc begin ---- main.cc end --
-- cls.h begin ---- cls.h end --
Re:クラステンプレートの継承? (スコア:1)