I have googled the error and found nothing. This is the last bug I've been trying to work out and the only I haven't been able to figure out. Thank you for your time.


I'm currently trying to test out a standard simple linked list class. I'm currently trying to templatize the class for ints/chars, then going to move on to templatizing it for a struct. The current driver is simply to ensure that I can create an object and get an item in there, then remove it successfully:

#include <iostream>
using namespace std;

#ifndef CSIMPLELIST_H
#define CSIMPLELIST_H
#include "CSimpleList.h"
#endif //CSIMPLELIST_H


int		main(void)
{
	auto	CSimpleList<char>	charObj;
        [b]ERROR: Expected initializer before '<' token [/b]

	auto	CSimpleList<int>	intObj;
        [b]ERROR: Expected initializer before '<' token [/b]

	auto	char				inChar = 'y';
	auto	int					inInt = 1;
	
	cout << "Number of items in charObj: " << charObj.m_numItems << endl;
        [b]ERROR: 'charObj' was not declared in this scope [/b]

	cout << "Number of items in intObj: " << intObj.m_numItems << endl;
        [b]ERROR: 'intObj' was not declared in this scope [/b]

	
	charObj.InsertItem(inChar, 1);
	intObj.InsertItem(inInt, 1);
	
	cout << "New number of items in charObj: " << charObj.m_numItems << endl;
	cout << "New number of items in intObj: " << intObj.m_numItems << endl;
	
	charObj.RemoveItem(1);
	intObj.RemoveItem(1);
	
	cout << "Final number of items in charObj: " << charObj.m_numItems << endl;
	cout << "Final number of items in intObj: " << intObj.m_numItems << endl;	
	
	return 0;
}

the redundant ifndef/endif is because I was getting a redefinition error, even though I have the safeguard in my .h file.

I'd appreciate any help I could get. I'll probably have more questions as this is just the basis for a VERY large project (relative to anything I've dealt with before) I'm working on.


I can provide the .h file upon request if that would be helpful in finding a solution.

The error is almost certainly in CSimpleList.h

BUT why is the guard around the CSimpleList.h. Three lines below,
should and almost certainly are in CSimpleList.h

#ifndef CSIMPLELIST_H
#define CSIMPLELIST_H
#endif //CSIMPLELIST_H

That might be your problem, by setting the guard, you have avoided loading CSimpleList.h,
since it has a repeat of those three lines.

It is normally considered bad practice to put a guard into the src code.

This article has been dead for over six months. Start a new discussion instead.