dorien
dorien

Reputation: 5387

using vector in c++ class definition

I have a mysterious problem. I keep getting a ‘vector’ does not name a type error when trying to define a variable in the tour class. The library seems installed correctly, since I can define vectors in main. According to many posts here I have checked for the right vector includes and std namespace. Still I get the error.

main.cpp

#include <vector>
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cmath>
#include <cstdlib>
#include "tour.h"
using namespace std;

int main () {

        //vector declaration works here
return 0;
}

tour.h

#ifndef TOUR_H_
#define TOUR_H_

#include<vector>
using namespace std;

class tour
{
    public:
      //variables
      int teamID;
      vector<int> tourseq; //this is where the error occurs

      //functions
      tour(int);

};

#endif /* TOUR_H_ */

tour.cpp

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

tour::tour(int id){
teamID = id;
}

What could be wrong here?

Upvotes: 0

Views: 1308

Answers (1)

utnapistim
utnapistim

Reputation: 27365

Instead of writing using namespace std; and vector<int> tourseq; consider writing std::vector<int> tourseq;.

You probably shouldn't put using namespace std; in your code anyway.

Upvotes: 2

Related Questions