V
V
Vadim Ushakov2021-09-21 18:56:17
C++ / C#
Vadim Ushakov, 2021-09-21 18:56:17

Registering a method when it is declared, is it possible?

It is necessary to implement a mechanism for saving data about certain class methods for further iteration and use. Note. code.

#include <iostream>
class Test {
    DREFLECT(); // Директива объявления необходимой части класса для сохранения методов.

     REFLECT void test_method() {std::cout << "Method1\n";}
     REFLECT void test_another_method() {std::cout << "Method2\n";}
}

Др. написание.

DREFLECT class Test { ...

.cpp
for(auto method, method_name : Test::REFLECT)
{
  std::cout << method_name << std::endl;
}


Is it possible to implement similar preprocessor macros for a class? Or is it worth implementing a class generator in a pseudo-language?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question