error: expected primary-expression before '[' token

I am getting this error in this function:
1
2
3
4
5
C:\Dev-Cpp\Chapter9\newOrderedArrayListType.cpp: In member function `void orderedArrayListType<elemType>::insert(int)':
C:\Dev-Cpp\Chapter9\newOrderedArrayListType.cpp:233: error: expected primary-expression before '[' token

Execution terminated
 

Here is the code of this function:
1
2
3
4
5
6
7
8
9
10
11
  template<class elemType>
void orderedArrayListType<elemType>::insert(int insertItem)
{
	if (this->length >= this->maxSize)
		cout << "The list is full." <<endl;
	else
	{
		list<int>[this->length] = insertItem;
		this->length++;
	}
}
list<int>[this->length] = insertItem;

This makes no sense. list<int> isn't an existing object. What is the name of the existing list that you're trying to put an item into?

Also, std::list does not support operator[] , so even if you did have a list to insert into, you can't insert using operator[]
One hour ago you did not know how to access templated base members. Now you know, but introduced this nonsense error? hm...
I got it working eventually!!!!
Here is the correct output:
1
2
3
4
5
6
7
8
C:\Dev-Cpp\Chapter9>arrayListType
Line 3: Enter numbers ending with -999
45 67 89 12 3 -999
Line 8: The list before sorting:
45 67 89 12 3

Line 12: The list after sorting:
3 12 45 67 89

Thank you to both of you Repeater and coder777
Topic archived. No new replies allowed.