dimanche 1 janvier 2023

#define template types doen't seem to work

suppose the following code:

#define __INIT_TYPE(type) { template<typename type>struct S{ };}

__INIT_TYPE(int);

int main(){
}

the second line produces the following error

Function definition for '\__INIT_TYPE' not found. Expected a declaration.
  1. Why does it happen? so far as I know the macro has to be replaced with the templated struct and which will be declared and then defined.

  2. If I am just missing something and there is a solution to q.1, is it considered a bad practice to nest types in the program with macros like this?

Aucun commentaire:

Enregistrer un commentaire