Hi,
I am trying to write a class that uses vectors that contain another class. When I compile my code using g++ I get the following error that I don't understand:
In file included from cars.cpp:5:
car.h:24: error: syntax error before `;' token
car.h:25: error: syntax error before `;' token

What is wrong with the syntax below?

#ifndef CAR_H
#define CAR_H


class Car {
    public:
        Car(int yr, const char *mk, const char *mod, int maxPass);
        ~Car();
        Person getDriver();
        Person getPassenger();
        int getSpeed();
        int howManyPassengers();
        void turnIgnitionOn();
        void turnIgnitionOff();
        void accelerate(int x);
        void decelerate(int x);
        void addDriver(Person name);
        void removeDriver();
        void addPassenger(Person name);
        void removePassenger();
        void showCar();
    private:
        int  year, maxPassengers, numberOfPassengers, speed;
        std::vector<Person> driver_seat;
        std::vector<Person> passengers;
        char make[20];
        char model[20];
        bool ignitionSwitch;
};

#endif

oh... I didn't realize that I needed to have an include in the header file.. i thought only the .cpp files needed them... thanks!

You can do it either way -- include <vector> in the *.cpp file before including car.h, or just add <vector> at the top of car.h. Either way works.

This question has already been answered. Start a new discussion instead.