Make a Collection of All Inherited Classes

Make a Collection of All Inherited Classes

Say you want to have several classes-modifiers, and you want to execute a certain virtual function for each of them. The ideal solution is to create an abstract class with a purely virtual function, inherit your implementation classes from this base class and make a collection of all the implementation classes. The problem is that, the user needs to remember to create exactly one copy of each implementation class and correctly “register” it. The following example helps to solve this problem by automatically creating exactly one instance of each implementation of the class modifier:

 #include template  class AutoMake{  virtual void trick() {t;} // virtual function uses _static variable  static T t;};template  T AutoMake::t;template   class Modifier : AutoMake{protected:  Modifier() {vec.push_back(this);}private:  std::vector vec;};class ModifierImpl1 : public Modifier {};class ModifierImpl2 : public Modifier {};That's all: already in main(...) function you will have _2 pointers inModifier::vec (with ModifierImpl1* and ModifierImpl2* types);
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes