01/10/2018, 15:08

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.
";
 }
 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;
}

Nguyễn Bá Tùng (Mrbachtung) viết 17:14 ngày 01/10/2018

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

Nguyễn Phạm Anh Quân viết 17:09 ngày 01/10/2018

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

Nguyễn Bá Tùng (Mrbachtung) viết 17:13 ngày 01/10/2018

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

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

Nguyễn Bá Tùng (Mrbachtung) viết 17:18 ngày 01/10/2018

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;
}
Bài liên quan
0