This is my code that adds two times.
This is the error message it gives -
It says =
q3(1483,0x105404580) malloc: *** error for object 0x600003904070: pointer being freed was not allocated q3(1483,0x105404580) malloc: *** set a breakpoint in malloc_error_break to debug
I did plenty number of checks and tried multiple things but everytime it doesn't works.
If I remove the destructor then its working otherwise the code is not working and always throwing the same bug!
This is my source code to add two times =
#include <iostream>
using namespace std;
class Time{
    int *min,*hour,*sec;
    
    public:
    Time(){
        min = new int;
        hour= new int;
        sec = new int;
        *min = 0;
        *hour = 0;
        *sec = 0;
    }
    void input(){
        cin>>*min>>*hour>>*sec;
    }
    friend void add(Time,Time);
    void display(){
        cout<<"The sum is = "<<"Min = "<<*min<<"Sec = "<<*sec<<"Hour = "<<*hour;
    }
    ~Time(){
        delete min;
        delete hour;
        delete sec;
    }
};
void add(Time t1,Time t2){
    Time t;
    *t.sec = *t1.sec + *t2.sec;
    *t.min= *t1.min + *t2.min;
    *t.hour = *t1.hour + *t2.hour;
    
    if(*t.sec>60){
        *t.min = *t.min + *t.sec /60;
        *t.sec = *t.sec % 60;
    }
    if(*t.min>60){
        *t.hour = *t.hour + *t.min /60;
        *t.min = *t.min % 60;
    }
    t.display();
}
int main(){
    Time t1,t2;
    cout<<"Enter value of 1st time = ";
    t1.input();
    cout<<"Enter value of 2nd time = ";
    t2.input();
    add(t1,t2);
    return 0;
} 

