I have code for c ++, I need to find out what the error is, describe it, and fix it if possible :)

#include<iostream> #include<queue> using namespace std; class stack { public: stack(int size); void push(int d ); int pop(); }; int main() { setlocale(LC_ALL,"RUSSIAN"); stack a(10); a.push(1); a.push(2); a.push(3); a.push(4); a.push(5); cout << a.pop() << ' '; cout << a.pop() << ' '; cout << a.pop() << ' '; cout << a.pop() << endl; } 

enter image description here

Closed due to the fact that Kromster , VTT , Jarvis_J , 0xdb , Kosta B are off topic . July 10 'in 21:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, Jarvis_J, 0xdb, Kosta B.
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Questions asking for help with debugging (“why does this code not work?”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question. Questions without an explicit description of the problem are useless for other visitors. - Kromster
  • Well, the main function in the class ... - MrBin
  • @MrBin Bad formatting, which made you think so - yes, but main not in class ... - Harry
  • Possible duplicate question: Link to unresolved external symbol (possible causes) - VTT
  • @Harry, right. The mistake came out - MrBin

2 answers 2

You have a stack that you create that you are working with. You have indicated to the compiler that it has a constructor and the member functions pop and push . The compiler took note of this.

You used all three in the program. The compiler did not object - you declared that they are (will be), he compiled, writing something like (in human language) - "linker, then the stack::pop function call, take it yourself you know where and turn it around. "

Linker is happy to try. He searches for these functions everywhere — in every file that is passed to him for linking (but you only passed one, with the given text), in libraries — but he finds nothing. Because you did not bother to write definitions ( implementations ) of these functions. And no one knows what you wanted to write in them - maybe the pop function should display a cartoon ... And neither the compiler nor the linker are accustomed to do anything without a command.

Well, the linker complains about the absence of your functions, how he can - that (in translation) met an unresolved symbol, which is referenced in the main function ...

  • Thank you, I completely forgot about the implementation of functions, thank you again) - Ruslan

You either have no implementation of the stack class, or you wanted to connect std::stack , but forgot to include the header file.

 #include <stack> 

I tend to the first.