10/23/10

method call chaining cpp

//in the name of Allah
#include
using namespace std;
class A{
  public:
    int a,b,c;
    A(){
    }
//     A seta(){a=1;cout<<"in a"<
//     A setb(){b=2;cout<<"in b"<
// //     A setc(){c=3;cout<<"in c"<
//     A setc(){c=3;cout<<"in c"<
//    
    A *seta(){a=1;cout<<"in a"<
    A *setb(){b=2;cout<<"in b"<
//     A setc(){c=3;cout<<"in c"<
    A *setc(){c=3;cout<<"in c"<
    void seta1(){cout<<"in a"<
    void  setb1(){cout<<"in b1"<
    void  setc1(){cout<<"in c1"<
   
    int  seta2(){cout<<"in a2"<
    int  setb2(){cout<<"in b2"<
//     int setc2(){cout<<"in c2"<
   
    A seta3(){a=0;cout<<"in a3"<
    A setb3(){b=-1;cout<<"in b3"<
    A setc3(){c=-2;cout<<"in c3"<
   
};
int main(){
  A a;
  a.seta()->setb()->setc();//a.seta().setb().setc();
  cout<<"=======================checkin        zzg===================="<
  cout<<"a="<<<"    b="<<<"     c= "<<
  //a.seta().setb1().setc1();//invalid use of void
  //a.seta2().setb2().setc2();//:24: error: request for member ‘setb2’ in ‘a.A::seta2()’, which is of non-class type ‘int
    a.seta3().setb3().setc3();
  cout<<"=======================checking3===================="<
  cout<<"a="<<<"    b="<<<"     c= "<<
 
}



















// //in the name of Allah
// #include
// using namespace std;
// class A{
//   public:
//     int a,b,c;
//     A(){
//     }
// //     A seta(){a=1;cout<<"in a"<
// //     A setb(){b=2;cout<<"in b"<
// // //     A setc(){c=3;cout<<"in c"<
// //     A setc(){c=3;cout<<"in c"<
// //    
//     A *seta(){a=1;cout<<"in a"<
//     A *setb(){b=2;cout<<"in b"<
// //     A setc(){c=3;cout<<"in c"<
//     A *setc(){c=3;cout<<"in c"<
//     void seta(){cout<<"in a"<
//     void  setb1(){cout<<"in b1"<
//     void  setc1(){cout<<"in c1"<
//    
//     int  seta2(){cout<<"in a2"<
//     int  setb2(){cout<<"in b2"<
//     int setc2(){cout<<"in c2"<
//    
// };
// int main(){
//   A a;
//   a.seta()->setb()->setc();//a.seta().setb().setc();
//   cout<<"=======================checking===================="<
//   cout<<"a="<<<"    b="<<<"     c= "<<
//   //a.seta().setb1().setc1();//invalid use of void
//   //a.seta2().setb2().setc2();//:24: error: request for member ‘setb2’ in ‘a.A::seta2()’, which is of non-class type ‘int
//  
// }

5 comments:

leave me messege