Arun Panneerselvam
Arun Panneerselvam

Reputation: 2335

visual c++ 2019 : typedef vector <class>, usage inside the class method

I'm developing a fleet management project using Microsoft Visual Studio 2019 (Professional). returned to VC++ after several years and developing a library. I have a class Vehicle and I need to group it using typedef vector

#include <vector>

using namespace std;
typedef vector<Vehicle> Fleet;   //error here. is it allowed to define like this in VS2019?

class Vehicle { 

  public: 
       Vehicle(unsigned id);
       void setVehiclesAvailable(Fleet& oldFleet) { 
         for(.... //iterate here to set availability for each vehicle in the old fleet.
       }
} 

I'm getting compiler error 'Vehicle':undeclared identifier (in typedef) Is there any alternate solution to define correctly?

Upvotes: 0

Views: 37

Answers (1)

heap underrun
heap underrun

Reputation: 2489

The error is due to Vehicle being undeclared at that point. You can forward-declare the Vehicle class before defining the Fleet type, like this:

class Vehicle;
typedef vector<Vehicle> Fleet;

Upvotes: 2

Related Questions