This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Const int passed to a templated method


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]