Program received signal SIGSEGV, Segmentation fault.
0x001c74a5 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/libstdc++.so.6
(gdb) where
#0 0x001c74a5 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/libstdc++.so.6
#1 0x0804b444 in Time::getTOD (this=0x0) at Time.cpp:63
#2 0x0804a4f0 in main (argc=2, argv=0xbffff7a4) at printsongs.cpp:102
(gdb) frame 1
#1 0x0804b444 in Time::getTOD (this=0x0) at Time.cpp:63
63 return timeofday;
(gdb) frame 2
#2 0x0804a4f0 in main (argc=2, argv=0xbffff7a4) at printsongs.cpp:102
102 << T->getMinute() << " " << T->getTOD() << endl;
(gdb)
Here are the codes:
Song s = songs.getNthSong (n);
Song defaultSong;
// Print out the last time it was played
if (!(s == defaultSong) ) {
Time *T = s.getLastPlayed();
cout << "Song #" << n << " is " << s.getTitle() << " by "
<< s.getArtist() << ". Last played at " << T->getHour() << ":"
<< T->getMinute() << " " << T->getTOD() << endl;
}
string Time::getTOD()
{
return timeofday;
}
This error happens when I add the operator= method
First of all, welcome:) And second, please use code-tags when posting pieces of code:) The segfault seems to be happening in the getTOD-function. A segfault usually occurs when you're trying to access something in memory which isn't there, so I'm guessing that somewhere along the line the timeofday-variable isn't being properly initialized.