I keep getting errors in my homework project whenever I build my code. I have a
ID: 3550117 • Letter: I
Question
I keep getting errors in my homework project whenever I build my code. I have a .h file and a .cpp file and this is the method that is in the .h file:
void push ( const std::string& s);
and here is the method that is in the .cpp file:
void push (SStack c){
string line;
ifstream myFile ( "all.last.txt" );
while(myFile.is_open()){
getline(myFile, line); //put file contents into array
c.push(line);
myFile.close();}
}
I keep getting: error: variable or field 'push' declared void| and error: 'SStack' was not declared in this scope| If someone could help me out that would be great, I'm really new at c++ and my teacher refuses to help. She's a bitch.
Explanation / Answer
The eror is in the line : ' void push (SStack c)'
If you declare a function in C++,it has to be in format:
returntype name ( parameter1, parameter2, ...) { statements }
parameter SStack is string,you missed the initialisation
so the line should be 'void push (string SStack c)'