199 C:\Projects\CPP\compiler\LRPAR\H\llist.h `elemNo' undeclared (first use this function)
////////////////////////////////////////////////////////////////////////////////
template <class Type>
class List {
protected:
Link<Type> first;
Link<Type> last;
int elemNo;
public:
friend class LIterator<Type>;
////////////////////////////////////////////////////////////////////////////////
template <class Type>
class ListSorted: public List<Type>
{
public:
virtual int Add(const Type Object);
};
////////////////////////////////////////////////////////////////////////////////
template <class Type>
int ListSorted<Type>::Add(const Type Object)
{
Link<Type>* NewObject = new Link<Type>(Object, 0);
Template support in GCC 3.x is not too hot, which is probably the cause of your problems. I think that you need to explicitly inline ListSorted<Type>::Add.
> I have modified the standard headers as per the instructions in the Dev-Cpp FAQ
You did what!? Post a link to the instruction. You should not have to modify any headers. However whatever you did it does not seem to be the issue here.
> 199 C:\Projects\CPP\compiler\LRPAR\H\llist.h `elemNo' undeclared (first use this function)
Post the complete text from the "Compile Log" tab, not one line from the "Compiler" tab.
The error occurred at line 199, so this is obviously just a fragment. Unfortunately we cannot tell which is line 199! Also being a fragment it is uncompilable, so we cannot reproduce or verify your finding. Staring at the code is not helping.
Start by posting the whole log, and identifying line - it may provide a clue for us to start with.
Some other unrelated points (ignore if you wish):
1) The inline keyword is redundant for functions defined within the class definition - your choice however.
2) Using Initialiser lists is potentially more efficient that 'body initialisation'. eg:
3) List() : first(0), last(0), elemNo(0){ }
4) The C++ STL already provides a <list> template class.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Clifford. I prefixed "this->" on elemNo and it seems to work fine. But now I am facing some problems where I have used templates. Working on this more to see if I can solve the problem myself.
I shall work on using the STL as suggested by you. Thanks once again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
199 C:\Projects\CPP\compiler\LRPAR\H\llist.h `elemNo' undeclared (first use this function)
////////////////////////////////////////////////////////////////////////////////
template <class Type>
class List {
protected:
Link<Type> first;
Link<Type> last;
int elemNo;
public:
friend class LIterator<Type>;
};
////////////////////////////////////////////////////////////////////////////////
template <class Type>
class ListSorted: public List<Type>
{
public:
virtual int Add(const Type Object);
};
////////////////////////////////////////////////////////////////////////////////
template <class Type>
int ListSorted<Type>::Add(const Type Object)
{
Link<Type>* NewObject = new Link<Type>(Object, 0);
..........
Kindly let me know in case more information is required.
Regards,
Hatim
Template support in GCC 3.x is not too hot, which is probably the cause of your problems. I think that you need to explicitly inline ListSorted<Type>::Add.
> I have modified the standard headers as per the instructions in the Dev-Cpp FAQ
You did what!? Post a link to the instruction. You should not have to modify any headers. However whatever you did it does not seem to be the issue here.
> 199 C:\Projects\CPP\compiler\LRPAR\H\llist.h `elemNo' undeclared (first use this function)
Post the complete text from the "Compile Log" tab, not one line from the "Compiler" tab.
The error occurred at line 199, so this is obviously just a fragment. Unfortunately we cannot tell which is line 199! Also being a fragment it is uncompilable, so we cannot reproduce or verify your finding. Staring at the code is not helping.
Start by posting the whole log, and identifying line - it may provide a clue for us to start with.
Some other unrelated points (ignore if you wish):
1) The inline keyword is redundant for functions defined within the class definition - your choice however.
2) Using Initialiser lists is potentially more efficient that 'body initialisation'. eg:
3) List() : first(0), last(0), elemNo(0){ }
4) The C++ STL already provides a <list> template class.
Clifford
Thanks Clifford. I prefixed "this->" on elemNo and it seems to work fine. But now I am facing some problems where I have used templates. Working on this more to see if I can solve the problem myself.
I shall work on using the STL as suggested by you. Thanks once again!