src/work/alpar/named-param-test4.cc
author ladanyi
Tue, 08 Feb 2005 11:27:03 +0000
changeset 1142 450f794dca81
child 1203 14f951664a63
permissions -rw-r--r--
more docs
     1 class AlgorithmDefaultTypes 
     2 {
     3 public:
     4   typedef int Adat;
     5 };
     6 
     7 template<class T = AlgorithmDefaultTypes>
     8 class AlgorithmTypes : public T 
     9 {
    10 public:
    11   template<class X>
    12   class SetAdat : public T { X Adat; };
    13 };
    14 
    15 template<class T = AlgorithmTypes<> >
    16 class AlgorithmDefaultDataFields : public T
    17 {
    18 protected:
    19   typename T::Adat adat;
    20 };
    21 
    22 template<class T = AlgorithmDefaultDataFields<> >
    23 class Algorithm : public T
    24 {
    25   int _intAdat;
    26 public:
    27   Algorithm() {};
    28   Algorithm(const T &tt) : T(tt) {};
    29 
    30   template<class X> class _SetAdat : public T {
    31     protected:
    32     X adat;
    33     public:
    34     _SetAdat() {}; //"Algorithm<>::_SetAdat<double> b;"-hez kell!!!!
    35                    // De az is rossz!!!!!
    36     _SetAdat(const T &t,const X& x) : T(t), adat(x) {};
    37   };
    38   
    39   template<class X>
    40   Algorithm<_SetAdat<X> > setAdat(const X &x) {
    41     return Algorithm<_SetAdat<X> >(_SetAdat<X>(*this,x));
    42   }
    43   
    44   Algorithm &setIntAdat(int i) {_intAdat=i;return *this;}
    45   //vagy:
    46   Algorithm &intAdat(int i) {_intAdat=i;return *this;}
    47   
    48   typename T::Adat run()
    49   {
    50     //Itt csinalunk valamit
    51     return typename T::Adat();    
    52   }
    53   ~Algorithm()
    54   {
    55     //Itt nem csinalunk semmit
    56   }
    57 };
    58 
    59 Algorithm<> algorithm() 
    60 {
    61   return Algorithm<>();
    62 }
    63 
    64 int main() 
    65 {
    66   Algorithm<> a;
    67 
    68   Algorithm<>::_SetAdat<double> b; b=b;//Ez itt nem az, amit szeretnenk!!! 
    69 
    70   Algorithm<>::SetAdat<double> c; c=c; //Ez itt nem az, amit szeretnenk!!!
    71 
    72   a.run();
    73   //  b.run();
    74   //  c.run();
    75   
    76   algorithm().run();
    77   algorithm().setAdat(5.2).run();
    78 }