I'm working on a lineEditor class (doubly linked list) and I'm switching it from using std::string to a template but I keep getting:
lineeditor.cpp(33) : error C2143: syntax error : missing ';' before '*'
when compiling. The code is:

template <class T>
int lineEditor<T>::getSize() {
	return maxLineCount;
}

template <class T>
node* lineEditor<T>::at(int n) { //error on this line
	fixLine(n);//makes sure number provided is valid
	node *curr;
	curr = this->head;
	for(int i = 1; i < n; i++)
		curr = curr->next;
	return curr;
}

and the header declaration is:

template <class T>
class lineEditor {
	struct node {
	public:
		node *pre;// previous node, NULL if first node
		node *next;// next node, NULL is last node
		T data;
	};
public:
	// constructors
	lineEditor(void);
	lineEditor(T);
	~lineEditor(void);
	// my functions
	void fixLine(int &);
	int getSize();
	node* at(int);
etc...

Any clue why this is happening? Thanks in advance.

Recommended Answers

All 5 Replies

Are you sure all your class declarations end with ';'?

Does your node class in any way depend on T?

Without more code I can't help further. Sorry.

I included the node struct in the header file it uses T data; and I'm sure all the semi colons are correct. I thought maybe i was missing one somewhere else but no matter where i move the at function it always goes to that line. I'm just switching it from a doubly linked list of strings to a template. I can't post anymore code really as its a school project, everyone else is just using string but my prof asked me to switch to template.

Well, the best I can guess is that node is an incomplete type because it depends on T.

You'll have to ask your professor for more help.

I finally figured it out...node is fine. I just had to replace:

template <class T>
node* lineEditor::at(int n) {
...
}

with:

template <class T>
typename lineEditor<T>::node* lineEditor<T>::at(int n) {
...
}

We haven't done anything with typename yet but I was able to find the solution by searching for C2143 on msdn. Thanks for trying.

Heh, well, at least you figured it out, even if you aren't aware that the solution is exactly as I predicted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.