Can't find the mistake

Hi this is the class I made.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #include<iostream>
  #include<vector>
  using namespace std;
  template <class T>
  class ShortestPathTable
  {
    private:
	
	struct box
	{
	T name;
	T parent;
	int value;
	};
	box* table;
	int sizeT;

public:
	ShortestPathTable(int size, vector<T> vec)
	{
		table=new box[size];
		sizeT=size;
		
	int i=0;
	for(vector<T>::iterator it=vec.begin();it!=vec.end();it++)
	{
		box[i].name=*it; //line 27
		box[i].parent= *it;
		box[i].value=-1;
		i++;
	
	}
	}
};


It has to make a "table" that is from boxes that has name, parent and a value. The constructor needs a size and a vector with names (like (1,2,3,4) or (a,b,c,d)) and it has to make 4 boxes with these names.
But it gives me some mistakes and they say " syntax error : missing ';' before '[' " on lines 27,28,29. I think the problem is in the for syntax but I can't find it.


Shouldn't lines 27-29 be table and not box? You also have to tell the compiler that it is a type. typename vector<T>::iterator....
http://stackoverflow.com/questions/11275444/c-template-typename-iterator
Last edited on
closed account (j3Rz8vqX)
Just from eye-balling, I would say "box" is a type and not a variable?

After, looking at it a bit, it's apparent that box is an object-type, not the name of your actual object; your object seems identified as "table":
1
2
3
		table[i].name=*it; //line 27
		table[i].parent= *it;
		table[i].value=-1;


Maybe, that's what you wanted.

Have fun.
Yes that was it. Really lame mistake but I guess my head is overloaded at the moment.
Thank you very much, guys !
Topic archived. No new replies allowed.