Last change
on this file since 1280:f2255b96c19c was
1052:172ce6c3ac6e,
checked in by Alpar Juttner, 15 years ago

Two examples showing a bit more convenient way to implement named parameters.

File size:
858 bytes

Line  

1  struct TR 

2  { 

3  int a; 

4  int b; 

5  int c; 

6  }; 

7  

8  template<class T> struct D : public T 

9  { 

10  

11  D(const T &tt) : T(tt) {}; 

12  

13  template<class X> struct TA : public T { 

14  X a; 

15  TA(const T &t,const X& x) : T(t), a(x) {}; 

16  }; 

17  

18  template<class X> D<TA<X> > setA(const X &x) { 

19  return D<TA<X> >(TA<X>(*this,x)); 

20  } 

21  

22  template<class X> struct TB : public T { 

23  X b; 

24  TB(const T &t,const X& x) : T(t), b(x) {}; 

25  }; 

26  

27  template<class X> D<TB<X> > setB(const X &x) { 

28  return D<TB<X> >(TB<X>(*this,x)); 

29  } 

30  

31  template<class X> struct TC : public T { 

32  X c; 

33  TC(const T &t,const X& x) : T(t), c(x) {}; 

34  }; 

35  

36  template<class X> D<TC<X> > setC(const X &x) { 

37  return D<TC<X> >(TC<X>(*this,x)); 

38  } 

39  ~D() 

40  { 

41  //Itt csinalunk valamit 

42  } 

43  }; 

44  

45  D<TR> d() 

46  { 

47  return D<TR>(TR()); 

48  } 

49  

50  int main() 

51  { 

52  d(); 

53  d().setA(5.5).setB(10).setC(1.5e12); 

54  } 

Note: See
TracBrowser
for help on using the repository browser.