Quote:Original post by 3dmodelerguy
I am sorry but i dont understand, what do you mean must be visable? I tried with the class members in the public instead of private but that does not help, could you please try to explian a little more?
A compiler only processes a file at a time. Outside of the generated object files that eventually get linked together, there is no communication happening between the different runs of the compiler over the individual source files (that's the "separate compilation" model). A
translation unit is composed of the .cpp file you're compiling, along with all the headers it includes (recursively). That translation must contain all the information the compiler needs to generate the object file.
When you declare a class template, you omit part of the information needed to compile the class, namely the template parameters so, obviously, the compiler cannot generate code for it yet. All it does is syntax-check it (which is why you need to add the typename keyword when using a dependent type, as the C++ grammar is ambiguous at that point).
It is only when you actually create a variable of that type that the compiler actually generates code for the class, using the appropriate parameters. The compiler cannot do anything with clist.cpp, since nowhere in its translation unit do you tell it what version of CustomList it should generate (which is what my previous comment was alluding to).
Additionally, a template class' member function are only compiled if they are actually used (this is, among other things, because not all member functions might work for all possible parameterizations of the class).
The problem with your code is that you have squirreled away the definition for the member functions into a separate file, which is not part of the main.cpp translation unit. The compiler sees that you are using CustomList<char>'s constructor so, at that point, it actually tries to compile it and generate the code for that instanciation of the class template. Unfortunately, the code for that constructor is not available. The compiler hasn't "seen" it in the current translation unit (hence it is not "visible").
The only way, with the current generation of compilers, to fix that problem is to include the member function definitions in every translation unit that is going to use the class. The simplest way to do that is, obviously, to put them in the header file that defines the class template. That is, you need to move the contents of clist.cpp over to clist.h.
As a final note, visibility and accessibility are two different concepts. The private members of a class are visible, but not accessible. When you try to access them improperly, the compiler tells you that they are private, instead of telling you that they do not exist (as it would for class, function or variable that hasn't been yet declared in the current translation unit).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan