Expected primary expression before 'unsigned'

Hi, I'm new to the forums and the language. I'm working on an assignment for uni, and am completely stumped as to the source of the error I keep on getting. Here's the problematic code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <list>
#include <vector>

using namespace std ;

list<unsigned> & topSort ( istream & idata )
{
  int numberOfRecords = 0;      // Holds number of records
  char list[80];
  idata.getline(list, 80);
  numberOfRecords = atoi(list);
  
  // Creates a reference to the list which will hold the ordered list of records
  list<unsigned> myList = new list<unsigned int>;
  
  list<unsigned> noPList;       // Creates a no-predecessor list
  
  // Creates a successor list equal to number of total records
  vector<list<unsigned> > successors(numberOfRecords);


And here are the error statements:

topSort.cpp: In function 'std::list<unsigned int, std::allocator<unsigned int> >& topSort(std::istream&)':
topSort.cpp:14: error: expected primary-expression before 'unsigned'
topSort.cpp:14: error: expected `;' before 'unsigned'
topSort.cpp:16: error: expected primary-expression before 'unsigned'
topSort.cpp:16: error: expected `;' before 'unsigned'
topSort.cpp:19: error: 'list' cannot appear in a constant-expression
topSort.cpp:19: error: template argument 1 is invalid
topSort.cpp:19: error: template argument 2 is invalid
topSort.cpp:19: error: expected unqualified-id before '>' token

There are more errors further down the code, but they all seem to be linked to these lines of code.

Any help would be greatly appreciated.
Look at line 15. You're maing a new list with the new operator, which returns a pointer. But, you are assigning that to a list object that is NOT a pointer! Which way do you want, pointer or no pointer?

Also, why are you making a vector of lists? Each element in the vector is a list...and each element in the list is an unsigned integer variable...
Last edited on
Oops, that's not how line 15 looks in my code. Here's the correct line:

list<unsigned>* myList = new list<unsigned>;

The errors don't appear to be because of that.

As for the second issue, that is what our professor wanted us to. Is it wrong? Or just unnecessary?

Anyways, thanks for the help.
Last edited on
Topic archived. No new replies allowed.