struct TR { int a; int b; int c; }; template struct D { T t; D(const T &tt) :t(tt) {}; template struct TA : public T { X a; TA(const T &t,const X& x) : T(t), a(x) {}; }; template D > setA(const X &x) { return D >(TA(this->t,x)); } template struct TB : public T { X b; TB(const T &t,const X& x) : T(t), b(x) {}; }; template D > setB(const X &x) { return D >(TB(this->t,x)); } template struct TC : public T { X c; TC(const T &t,const X& x) : T(t), c(x) {}; }; template D > setC(const X &x) { return D >(TC(this->t,x)); } ~D() { //Itt csinalunk valamit } }; D d() { return D(TR()); } int main() { d(); d().setA(5.5).setB(10).setC(1.5e12); }