I was practicing with classes in C++, and I wrote this simple program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
struct timer{int hour;};
class Time{
private:
timer* time;
public:
Time(){time->hour=0;}
};
int main (void)
{
Time j,k;
}
I keep getting a segmentation fault. The debugger showed that after line 10, this=0x28ff18. I can't think of a reason why that is happening. Also, if in main I only declare Time j, then the program runs fine. Furthermore, if instead of using struct, I simply use int hour, the program runs fine. I don't understand why the struct is causing a problem?