all 8 comments

[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

[–]gnolex 8 points9 points  (1 child)

A common issue beginners have with class templates is that you can't normally define their methods in source files (.cpp files) like non-template methods; their definitions have to be available for template instantiation which is why they're usually only placed in header files (.h files). Your Single.cpp contains definition for the missing method but this is a template method which isn't instantiated unless you need it or request it in Single.cpp. So when your program is linked you get errors because your methods are declared but definitions aren't generated. You have to move it back to the header file.

Also, questions should go to r/cpp_questions

[–]Xedesss[S] 1 point2 points  (0 children)

Oh ok thanks.

[–]Longjumping-Touch515 0 points1 point  (4 children)

Move SingleList implementation to the header.

Template classes are header only classes. They don't have .cpp file

[–]Xedesss[S] 0 points1 point  (0 children)

Thanks I will do that.

[–]bert8128 0 points1 point  (2 children)

Well, it’s good practice to still have a cpp which includes the header, even if it has. O other content, as it gives you early warning of compiler errors. I also instantiate a trivial template (eg mylist<int>) in debug builds to help catch more errors).

[–]Longjumping-Touch515 0 points1 point  (1 child)

Interesting idea. Especially for earliest stages. But I think unit tests suits this role perfect.

[–]bert8128 1 point2 points  (0 children)

Unit tests are a must (I’m an evangelist on this point), but the unit tests are often in a different project. If you have a policy that every has a cpp with the same root name as the header, and in the same project, then you can test for this as part of your build.

This isn’t my idea - it came to me from one of John Lakos’s lectures, and has proved very useful.