mercredi 31 juillet 2019

Call Before Main using a Static Object Constructor = Warning Unused Static

I know that there are a few questions similar to this one, but I believe that this one is diferent in the details.

I'm trying to "register" some cases, that should call a Class::instance("some string") and for that I created

class register { 
      register::register(const char *a) {
           Class::instance()->register(a);
      }
}

that I use as follows:

namespace {
     auto a = register("abc");
     auto b = register("cbd");
}

This first gave me the warning "non pod static variable", but it worked. Then I tried to use a second approach:

namespace { 
    int silence_warning = (Class::instance()->register("abc"), 0);
}

also works, but a new warning: "warning, not used static variable"

There's anything I can do to get rid of both warnings and still be able to call this before main?

Aucun commentaire:

Enregistrer un commentaire