Files
Training-Team2-Zenvy-Jan26/Trenser.Zenvy/Trenser.Zenvy/factories/Factory.h
T

32 lines
746 B
C++

/*
* File: Factory.h
* Description: Provides a generic factory utility to create shared_ptr instances of objects.
* Author: Ajmal J S
* Created: 01-04-2026
*/
#pragma once
#include <memory>
#include <utility>
class Factory
{
public:
/*
* Function: getObject
* Description: Creates and returns a shared_ptr to an object of type T.
* Parameters:
* T - the type of object to be created
* Args - constructor arguments forwarded to T's constructor
* Returns:
* std::shared_ptr<T> - a shared pointer managing the newly created object
*/
template<typename T, typename... Args>
static std::shared_ptr<T> getObject(Args&&... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
};