c++ - Is it possible to resolve static members similarly to overloading the member access operator for another type? -


i not sure call it, possible commented out line reflects?

template <typename t> class test { public:     test(t& t) : m_t(t) {}     t* operator->() { return &m_t; }  private:     t& m_t; };  class { public:     static const int integer = 0;      void function() {} };  int main() {     a;      test<a> test(a);     test->function();      // similar doing test<a>::integer?      return 0; } 

well, why don't do:

test->integer; 

you can access static members same way non-static ones (i.e. instance variable).

the other option define in test:

template <typename t> class test { public:   typedef t value_type;   // ... }; 

in case able do:

test<a>::value_type::integer; 

which avoid need of creating instance of test<a>.

at last, if using c++11 , test follows smart pointers conventions, have:

std::pointer_traits<test<a> >::element_type::integer; 

which has advantage work if replace test<a> a*.


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -