-2

My project is to build a stack in C++, And I implemented it using array ,but I have 6 Errors: all of them LNK2019 Unresolved external symbol to some functions implementation in the .CPP file I know this is a linker errors , the problem occurred when I Divided My code into Header files .h and implementation files .cpp but the syntax is alright and the program The program has run correctly when I had to test the code in on file :the main file ,any solutions please?

this is the link of code: https://github.com/MohamedYehiaShahin/stack-usin-array-c-

  • 2
    Please post your code – Casey Mar 03 '21 at 18:06
  • Make absolutely certain that when you split up the program into multiple files that Visual Studio knows that it is expected to compile and link the new files. Depending on how you created the new files, Visual Studio may know they exist and show them, but not realize that they're part of the project and have to be built. One quick test too make sure the files are being built is to insert an obvious mistake, like a line of random garbage, into one of the new files and see if the compiler complains when you build the program If it doesn't complain, you'll have to add the file to the project. – user4581301 Mar 03 '21 at 18:11
  • As for formal answers we can't give one without a lot more information and the question will likely be closed as a duplicate of a huge omnibus question that lists virtually every possible cause of linker errors. Good luck finding the correct solution for your specific problem in the dozens of pages of answers With more information the question will likely still be closed, but at least we can point you at the exact solution. – user4581301 Mar 03 '21 at 18:14
  • Here's a link to the omnibus question on the off chance you can find your answer without help: [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816) – user4581301 Mar 03 '21 at 18:20
  • i had edit my post and the link to the code in it – mohammed yahya Mar 03 '21 at 18:51
  • 1
    Links to code/repos are discouraged due to link rot. Please post your code inside the actual question by surrounding the text with three backticks on their own line. Optionally if you want to help the syntax highlighter, you can append the first set of backticks with a language specifier: `cpp` – Casey Mar 03 '21 at 18:55
  • @Casey I recently found you can escape the backticks in comments to make the explanation a bit easier: `\`\`\`cpp\`\`\`` – user4581301 Mar 03 '21 at 18:59
  • @Casey ,This is the first time I ask a question ,sorry – mohammed yahya Mar 03 '21 at 19:09
  • 1
    @user4581301 TIL backticks can be escaped...too bad newlines in comments can't be a thing. – Casey Mar 03 '21 at 19:22
  • Unfortunately I can imagine the spam comment abuse if newlines were permitted. – user4581301 Mar 03 '21 at 19:28

1 Answers1

0

Since you didn't post your code, I can only guess. If you are implementing your stack using a template (very common) then you may see this error if you define your template functions/methods in a separate .cpp file. Typically template functions & classes are defined inline or contain their definitions within the same header file as their declarations.

Woodford
  • 3,746
  • 1
  • 15
  • 29
  • 1
    I strongly recommend not guessing. Instead move on to question that can be given a concrete answer. If your guess is correct, this question would be a duplicate of [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021) and should be closed rather than answered again. – user4581301 Mar 03 '21 at 18:17
  • As you cannot yet comment, move on to another post ;) – limserhane Mar 03 '21 at 18:18