-
error with functions
hey, if you could just check out my code, i've spent soo long on it already, and i cant seem to figure out WHY this doesnt work when the code for the functions is pretty simliar!
all im doing is getting input from the stream and storing into a variable.
Code:
//animals.h
class animals {
public:
void set_title(string);
void set_G(string);
private:
string G;
string title;
};
//animals.cpp
//...
void Item::set_title(string x) {
title = x;
}
void Item::set_G(string x) {
G = x;
}
Code:
//main.cpp
// ...
Animals * temp;
string title;
string G;
out << "Enter title: ";
getline(in, title);
temp->set_title(title);
out << "Enter genre: ";
getline(in,G);
temp->set_G(G); //segfaults right here
-
> Animals * temp;
No memory has been allocated
Animals * temp = new Animals;
-
OMG you have got to be joking, that WAS the error!!!
geeeeeezus! how long did i spend on this shnizzle just for that crappy eerror!
thanks mate
-
don't worry, i've spent more time on easier problems....sometimes you get it stuck in your head that that the problem has to do with one thing (ussually it's your first attempt at it), but it's actually something completely different and fundamental....
ussually when i get stuck, i'll re-type the code without looking at the original code and can find the stupid mistakes i made that way...ussually i end up typing just a few lines and go "oh! i'm a dipsh-.....i forgot to do 'this'"....