You may need a little polymorphism here. Does this work for you?
First a base class:
- class Geofence
-
{
-
public:
-
-
-
};
Then derived classes for each of your geofences.
- class Triangle :public Geofence
-
{
-
public:
-
-
-
private:
-
vector<int> arr; //your triangle data type
-
-
};
-
class Rectangle :public Geofence
-
{
-
public:
-
-
-
private:
-
vector<int> arr; //your rectangle data type
-
-
};
-
The idea is you create a Triangle or Rectangle object and use it as a base class pointer. So all your code uses only the base class.
To create your objects, use a factory. This oe creates a triangle or rectangle object based on specific input:
- class GeofenceFactory
-
{
-
public:
-
Geofence* Create(std::string fence);
-
};
-
-
Geofence* GeofenceFactory::Create(std::string fence)
-
{
-
if (fence == "Triangle")
-
{
-
return new Triangle;
-
}
-
if (fence == "Rectagle")
-
{
-
return new Rectangle;
-
}
-
}
-
Then in main() you create your factory on the heap, create your geofence object (or objects) then delete the factory.
- int main()
-
{
-
GeofenceFactory* f = new GeofenceFactory; //create factory
-
Geofence* triangle = f->Create("Triangle");
-
-
Geofence* rectangle = f->Create("Rectangle");
-
-
delete f;
-
-
//you are now ready for business
-
-
}
In this scheme any fuction you write that has a base class pointer or reference argument can use the derived objects. The vectors have been hidden you you don't need the same implementation for each type of geofence.