Gặp lỗi "SIGILL on thread" nhưng không biết nguyên do gì

Chào tất cả,
Mình đang lập trình OOP C++ trên android dùng app Mobile C của Lee Jeong Seop. Tìm trên stackoverflow thì nó nói lỗi này là phụ thuộc vào phần cứng và nền tảng hệ điều hành gì đó, nhưng mình thấy còn mơ hồ quá, xin các bác chỉ giáo thêm. Code mình đây

#include <iostream>
using namespace std;
class Time {
 int h, min,sec;
 public :
 Time(int a, int b,int c) {
  h = a;
  min = b;
  sec = c;
 }
 Time() {
  h = min = 0;
 }
 void show() {
  cout<<h<<" Hours "<<min;
  cout<<" minutes "<< sec<<" sec.\n";
 }
 Time operator=(Time t){
  h = t.h;
  min = t.min;
  sec = t.sec;
  return Time(h,min,sec);
 }
friend Time operator>>(istream &ob,Time &t);
friend Time operator<<(ostream &ob,Time &t);
};
Time operator>>(istream &ob,Time &t){
 cout<<"Enter Time ";
 ob>>t.h;
 ob>>t.min;
 ob>>t.sec;
}
Time operator<<(ostream &ob,Time &t){
 ob<<t.h<<"::"<<t.min;
 ob<<"::"<< t.sec<<endl;
}
int main() {
 Time t;
 cin>>t;
 cout<<t;
 t.show();
 Time t2,t3(5,10,30);
 t2 = t3;
 t3.show();
  return 0;
}

Hix có bác nào biết lỗi này hok?

Học lại operator overloading nhé em, trong trường hợp này operator= sai cú pháp, phải là Time& operator=(const Time& t)
http://en.cppreference.com/w/cpp/language/operators

1 Like

Bỏ phần t2 = t3 nó vẫn bị anh. Hình như là tại toán tử <<Còn nữa, tại toán tử >>khi em nhập dữ liệu xong thì nó chạy lại hàm main

Ok đã sửa lỗi xong, thank anh nhiều

friend istream& operator>>(istream &ob,Time &t);
friend ostream& operator<<(ostream &ob,const Time &t);
};
istream& operator>>(istream &ob,Time &t){
 cout<<"Enter Time ";
 ob>>t.h;
 ob>>t.min;
 ob>>t.sec;
 return ob;
}
ostream& operator<<(ostream &ob,const Time &t){
 ob<<t.h<<"::"<<t.min;
 ob<<"::"<< t.sec<<endl;
 return ob;
}
1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?