expected type specifier

I have this line of my code .. vector <Team *> teams(4);

visual C++ compiler says "expected type specifier" when i hover the cursor over 4 in teams(4) .

If if i change the line to
vector <Team *> teams(a typename like int,double,etc) there is no longer any error.

But i want to create the Team * vector with 4 elements and i dont think im doing anything wrong.

Any suggestions?
I don't know why you get an error. Maybe it would be easier to say what's wrong if you posted real code.
here is the code

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
#ifndef GROUP_H
#define GROUP_H

#include <vector>
#include "Team.h"
using namespace std;

#define TEAMS_PER_GROUP 4
class Group : public Team
{
public:
	Group(char &);	
	void groupTable(vector <Team *>&);	//show group table.
	void setFixture(vector <Team *> & );
	char getName() const;

	void getNextFixture();	//set team1 and team2 of next fixture
	
private:

	char name; //group name
	void sortTeams(vector <Team *> &) const;
	vector <Team *> teams(4);  //this is the line concerned

	string team1,team2;
};	
#endif 


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
35
36
37
38
39
40
41
42
43
44
45
#ifndef TEAM_H
#define TEAM_H

#include <string>
using namespace std;

class Team
{
public:
	Team();
	Team(string &,int  = 0, int = 0, int  = 0, int = 0, int  = 0, int = 0);		//constructor;
	
	void setName(string &);
	string getName() const;

	void setPlayed(int);
	int getPlayed() const;

	void setWin(int);
	int getWin() const;

	void setDraw(int);
	int getDraw() const;

	void setLoss(int);
	int getLoss() const;

	void setPoints(int);	
	int getPoints() const;

	void setNext(bool) const;
	void setCur(bool) const;

private:
	string name;
	int played;
	int win;
	int draw;
	int loss;
	int points;

	bool next;		
	bool current;
};
#endif 
You can't specify the constructor in the class body like that.

Just leave out the constructor in the class body
 
vector <Team *> teams;

and specify the constructor in the constructor initialization list.
1
2
3
4
Group::Group(char &)
:	teams(4)
{
	...

In C++11 (or later) you can do it in the class body if you want, by using curly brackets instead of normal parentheses.
 
vector <Team *> teams{4};
Last edited on
Thanks. it works
Topic archived. No new replies allowed.