Can I adress a static const member in a template without a template argument?

I have something like this:

1template<typename T> 2class Master{ 3 public: 4 static const ALLEGRO_EVENT_TYPE STATIC_MEMBER; //It really is an unsigned int 5}

1class A; 2Master<A> ma;

1#include "master.hpp" 2class B{ 3 void check_event(ALLEGRO_EVENT_TYPE x){ 4 if(x==Master::STATIC_MEMBER) 5 zomfg(); 6 else 7 rofl(); 8 } 9};

Including the header for class A, just to type "Master<A>::STATIC_MEMBER" seems messy, and saying "Master<any type, because the static member doesn't depend on it>::STATIC_MEBER" seems wrong.
Is there a way around this... most preferably pre C++11. Thanks in advance.

Stas B.

I don't think so. I guess you could do Master<void>::STATIC_MEMBER or something. The meaning is clear and there are no practical implications. Arguably, if you need to use that constant in places that don't need the rest of the class, it shouldn't be a part of it at all. The compiler will copy your entire template class into helper.hpp just for that single constant and that's not exactly optimal.


Actually, don't do the void thing. It doesn't work. :-/


Could you try having a class on top of it?

class MasterParent {

template<typename T>
class Master<T> : public MasterParent {
   //rest of your class that does use the template

(this is just a guess...)


Hahahahaha :-[
Actually class A and B were the same one, only in my head were they separated things.(Because in this case the class actually does two things). That solves it ;D
Also, I've found this method that gave no errors[1]

1#include "master.hpp" 2 3//Forward declaration 4class unknown; 5 6void check_event(ALLEGRO_EVENT_TYPE x){ 7 if(x==Master<unknown>::STATIC_MEMBER) //Compiler needs no further information to resolve this 8 zomfg(); 9 else 10 rofl(); 11}

J-Gamer, I have considered that option, but I would consider that more of a work-around. Luckily I've found this.
Stas, and J-Gamer thanks for trying. Here's some of my fails, for laughs: ;D

template Master::STATIC_MEMBER;


  1. I haven't done linking yet, but I believe this is one of those cases for which C++'s advanced name mangling was invented. And obviously you need to instantiate the template /somewhere/.
Thread #610302. Printed from