This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Const int passed to a templated method
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: "Angelo Calafato" <angelo dot calafato at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Thu, 28 Sep 2006 15:54:41 +0200
- Subject: Re: Const int passed to a templated method
- References: <ed58495a0609280341r3c85bc2y299ac3b77a0bb771@mail.gmail.com>
> class Display
> {
> public:
> static const int TYPE1;
> static const int TYPE2;
>
> Display(const int& t) : _t(t) {}
> virtual void process() {}
> private:
> const int _t;
> };
> const int Display::TYPE1 = 1;
> const int Display::TYPE2 = 2;
>
> class DisplayType1 : public Display {
> public:
> DisplayType1() : Display(Display::TYPE1) {}
> void process() { std::cout << "Type1\n"; }
> };
>
> class DisplayType2 : public Display {
> public:
> DisplayType2() : Display(Display::TYPE2) {}
> void process() { std::cout << "Type2\n"; }
> };
This is not the correct list for this type of question. Instead, I
suggest you read "Modern C++ Design" by Andrei Alexandrescu. He also
has a useful website: I suggest you look at it.
That said:
class display_policy_type1
{
void process() { std::cout << "Type1\n"; }
};
class display_policy_type2
{
void process() { std::cout << "Type2\n";
};
template<typename Policy>
class display : public Policy { };
is the usual design.
-benjamin