InstanceCreator::Invoke

Contents

InstanceCreator::Invoke#

template<typename ...Args>
inline NamedInstance<GetClassOfWorker<Creator>> YR::internal::InstanceCreator::Invoke(Args&&... args)#

Execute the creation of an instance and construct an object of the class.

 // Example: Create an instance and call a member function
 int main(void) {
     YR::Config conf;
     YR::Init(conf);

     auto ins = YR::Instance(SimpleCaculator::Constructor).Invoke(); // Create an instance
     auto r3 = ins.Function(&SimpleCaculator::Plus).Invoke(1, 1);    // Call a member function
     int res = *(YR::Get(r3));                                     // Get the result
     return 0;
}

Note

This method constructs an instance of the class and ensures that the instance can only execute member function requests of the class. The returned named instance allows you to call member functions of the class.

Warning

Ensure that the provided arguments match the constructor’s expected types and number exactly to avoid compilation errors. The instance created by this method is designed to work with member functions of the class only.

Template Parameters:
  • F – The type of the worker function used to construct the instance.

  • Args – The types of the arguments required by the worker’s constructor.

Parameters:

args – The arguments required by the worker’s constructor. The types and number of arguments must match the constructor’s definition exactly. Ensure that the arguments passed match the expected types precisely to avoid issues caused by implicit type conversions.

Returns:

NamedInstance<GetClassOfInstance<F>>, A named instance that can be used to call member functions of the class using the Function method, suitable for object-oriented programming scenarios.