How to force a static member to be initialized?

后端 未结 5 1574
悲&欢浪女
悲&欢浪女 2020-11-27 05:46

Consider this example code:

template
char register_(){
    return D::get_dummy(); // static function
}

template
struct Foo{
           


        
5条回答
  •  日久生厌
    2020-11-27 05:48

    Is there any way to force dummy to be initialized (effectively calling register_) without any instance of Bar or Foo (no instances, so no constructor trickery)?

    Wouldn't this be sufficient?

    std::cout << Foo::dummy;
    

提交回复
热议问题