templates and "is not a type" error

Hi, all. I expect express myself clearly,

I'm programming a simple template application. More precisely a list. I have 3 classes, one for scan the list (CIterator) and another with the list (CLink).

I've written, for every class, declaration and implementation in the same file (someone told me that there are some limitations in compilers that lead to this aproach). So the result is two files .h one per class.

If I'm in CLink file, and I need to use the other, I make the so-called predeclaration, i.e.

Code start: -----------------

// File cLink.h
template <typename T> CIterator; // here it is predeclaration

// File citerator.h is included in compilation through a makefile

template <typename T> class CLink
{
// All stuff about CLink, where in some point CIterator is used
CIterator Iterator; // say this is line 55
};

Code end: ----------------------

I have both files included in a makefile.

OK. Launch compiler and it complains in line 55 saying "CIterator is not a type"

I'm working in linux, debian dist. whith g++ (I don't remember version of g++. Sorry but I'm not in front of my working computer), All I can say now is that the last stable distro: etch.

I've searched g++ doc and all I found is that option -x could have something to do with this, but the experience says it doesn't.

To me, it looks like I've missed something trivial because I know this scheme works in Visual C++.

Could someone give any advice?
Thank you very much.



As you note it the CIterator is a template which expects a type to be supplied for the purpose.
template <typename T> Citerator; // here T is an operator which the definition operates on and you need to supply in its use/declaration

I could say it probably expecting you to provide the type you want to use for template, like:

CIterator<int> Iterator; // say this is line 55

Try it out. Good luck :)
Try it out as
typename CIterator<T> Iterator; // typename tells it is a type and T is your supplied argument for CIterator

Good luck :)
Thanks a lot, satm2008. That was it. I missed <T> in my declaration.

Anyway I've to add that, due to the huge amount of modifications my code has suffered, I've ended up with all the code put in a single file. Later I'll try to separate it again in .h files and try.

Do you want to be kept informed? ;-)

Now I have different problems.

Sorry for the delay answering in this forum.
Topic archived. No new replies allowed.