The declarations belong to the header files, and the implementations to the cpp files.
So lines 7 till 23 go to Node.h , lines 25 till 74 to Node.cpp, line 77 till 91 to LInkedList.h, 93 till 200 to LinkedList.cpp, and the remainder to main.cpp.
LinkedList.h and Node.cpp must include Node.h, LinkedList.cpp and main.cpp need including LinkedList.h.
A rule of Thumb is that you need include all the header files which provide the declarations of these types which you want using in your cpp (or h) file.
With template classes, the compiler has to have access to the entire definition of the template at the point where the class is instantiated. It's not enough to simply proved the method declarations in the header and rely on the linker to sort it out, as with normal classes; you need to have the entire definition available to the compiler.
In practise, this means that you want the entire definition of the class, including the full method definitions, in the header file.
Everyone above has very good points that will work. Although as lastchance says it worked in G++, but not everyone has G++ for a compiler.
As i have recently read here what you can do is say put the class "Node" in its ".hpp" file and put the member functions in a ".cpp" type file, but give it the extension ".imp" then at the bottom of the class after the closing } put #include "Node.imp" and you will have the same thing as previously mentioned.
I understand the concept here, but have not had the opportunity to test it yet. I think I will try it with your program.
Although as lastchance says it worked in G++, but not everyone has G++ for a compiler.
That's a strange comment. What about lastchance's solution do you think is specific to g++? What about lastchance's solution do you think might fail on other compilers?
What about lastchance's solution do you think is specific to g++?
Maybe. It does not work in my VS2017 or when I used VS2015.
I'm surprised. You can also compile it from the command line as cl.exe main.cpp
(cl.exe being the C++ compiler associated with Visual Studio).
The only point that I was trying to make is that, whatever compiler is used, it is only directed at the main.cpp file, as that will "pull in" the headers as necessary.
I never use IDEs, so I have no idea if your header files were in the right place to be found. What exactly happened when you tried to compile main.cpp within Visual Studio?
As always, "it does not work" or "it did fail" are not useful problem statements. Tell us the error messages you got were, and maybe we can help solve the problem.
There is nothing in lastchance's solution that is dependent on a particular compiler. In fact, he's fundamentally done the same thing that you suggested in your own solution.
When i create new class in Code::Blocks from wizard
it create class splitted into header file and source file
and thats why i tried to divide code into
Node.h and Node.cpp
LinkedList.h and LinkedList.cpp
main.cpp
lastchance you suggest that i should put class and method definitions
in one header file ?
Human prefers familiar conventions and short blocks of code. If there are more than one human, they have to agree on conventions (so they don't have to guess).
IDE is full of IF x THEN y rules, like the "create class wizard" that conveniently and consistently fills in trivialities for you, or the syntax highlight. If your file naming convention differs, the IDE does not know what is the Right Thing. IDE cannot guess. You can probably define a new wizard for creating templates, if there is no such thing already.
You're not reading what we're telling you. Yes, for normal classes, it's good to split into header and source files.
However, for template classes, things are different. For template classes, you need the entire definition in the translation unit where the class is used (*) .
Effectively, that means putting the whole thing into header files that are included. You can split it between multiple included files, as lastchance and Handy Andy have explained, if you want to maintain the illusion of separating the implementation from the declaration.
When i create new class in Code::Blocks from wizard it create class splitted into header file and source file and thats why i tried to divide code into Node.h and Node.cpp ...
Note that a class template is not a class. It's a recipe for creating classes. Different rules apply.