Announcement

Collapse
No announcement yet.

[help]Nạp chồng nhập, xuất tham số con trỏ!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [C++] [help]Nạp chồng nhập, xuất tham số con trỏ!

    giúp mình với! code này run được nhưng báo lỗi trong khi nhập x, y. Mình nghĩ lỗi ở đâu đó, nhưng mình ko sửa được..

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<iomanip.h>
    
    class Toado2D
    {
          private:
             int x;
             int y;
             Toado2D *next;
          public:
             Toado2D()
             {
                x = 0;
                y = 0;
             }
             Toado2D(int x, int y)
             {
                this->x = x;
                this->y = y;
             }         
             Toado2D operator<=(Toado2D M);
             Toado2D operator=(Toado2D M);
             Toado2D operator>(Toado2D M);
             friend istream &operator>>(istream &s, Toado2D *M);
             friend ostream &operator<<(ostream &s, Toado2D *M);
    };
    
    istream &operator>>(istream &s, Toado2D *M)
    {
       cout<<"Nhap toa do (x, y): ";
       s>>M->x>>M->y;
       return s;
    }
    /* ostream &operator<<(ostream &s, Toado2D *M)
    {
       cout<<"Toa do da nhap \n";
       s<<"("<<M.x<<","<<M.y<<")"<<endl;
       return s;
    } */
    
    main()
    {
         Toado2D *A;
         cin>>A;
         getch();
    }

  • #2
    Originally posted by lytieulong_269 View Post
    giúp mình với! code này run được nhưng báo lỗi trong khi nhập x, y. Mình nghĩ lỗi ở đâu đó, nhưng mình ko sửa được..

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<iomanip.h>
    
    class Toado2D
    {
          private:
             int x;
             int y;
             Toado2D *next;
          public:
             Toado2D()
             {
                x = 0;
                y = 0;
             }
             Toado2D(int x, int y)
             {
                this->x = x;
                this->y = y;
             }         
             Toado2D operator<=(Toado2D M);
             Toado2D operator=(Toado2D M);
             Toado2D operator>(Toado2D M);
             friend istream &operator>>(istream &s, Toado2D *M);
             friend ostream &operator<<(ostream &s, Toado2D *M);
    };
    
    istream &operator>>(istream &s, Toado2D *M)
    {
       cout<<"Nhap toa do (x, y): ";
       s>>M->x>>M->y;
       return s;
    }
    /* ostream &operator<<(ostream &s, Toado2D *M)
    {
       cout<<"Toa do da nhap \n";
       s<<"("<<M.x<<","<<M.y<<")"<<endl;
       return s;
    } */
    
    main()
    {
         Toado2D *A;
         cin>>A;
         getch();
    }
    Toado2D *A;
    cin>>A;
    Con trỏ A chưa đc cấp phát bộ nhớ thì lỗi chứ sao.

    Im a british accent lover

    Comment


    • #3
      trời! Ngớ ngẩn quá....
      Cảm ơn pan nhiều nha!

      Comment

      LHQC

      Collapse
      Working...
      X