<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Can I adress a static const member in a template without a template argument?</title>
		<link>http://www.allegro.cc/forums/view/610302</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 27 May 2012 22:56:39 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have something like this:
</p><div class="source-code"><div class="toolbar"><span class="name">master.hpp</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="k1">template</span><span class="k3">&lt;</span><span class="k1">typename</span> T&gt;
<span class="number"> 2</span><span class="k1">class</span> Master<span class="k2">{</span>
<span class="number"> 3</span>  public:
<span class="number"> 4</span>  <span class="k1">static</span> <span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_TYPE"><span class="a">ALLEGRO_EVENT_TYPE</span></a> STATIC_MEMBER<span class="k2">;</span> <span class="c">//It really is an unsigned int</span>
<span class="number"> 5</span><span class="k2">}</span>
</div></div><p>

</p><div class="source-code"><div class="toolbar"><span class="name">implementation.hpp</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="k1">class</span> A<span class="k2">;</span>
<span class="number"> 2</span>Master<span class="k3">&lt;</span>A&gt; ma<span class="k2">;</span>
</div></div><p>

</p><div class="source-code"><div class="toolbar"><span class="name">helper.hpp</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#include "master.hpp"</span>
<span class="number">  2</span><span class="k1">class</span> B<span class="k2">{</span>
<span class="number">  3</span>  <span class="k1">void</span> check_event<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_TYPE"><span class="a">ALLEGRO_EVENT_TYPE</span></a> x<span class="k2">)</span><span class="k2">{</span>
<span class="number">  4</span>    <span class="k1">if</span><span class="k2">(</span>x<span class="k3">=</span><span class="k3">=</span>Master::STATIC_MEMBER<span class="k2">)</span>
<span class="number">  5</span>      zomfg<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>    <span class="k1">else</span>
<span class="number">  7</span>      rofl<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>  <span class="k2">}</span>
<span class="number">  9</span><span class="k2">}</span><span class="k2">;</span>
</div></div><p>
Including the header for class A, just to type &quot;Master&lt;A&gt;::STATIC_MEMBER&quot; seems messy, and saying &quot;Master&lt;any type, because the static member doesn&#39;t depend on it&gt;::STATIC_MEBER&quot; seems wrong.<br />Is there a way around this... most preferably pre C++11. Thanks in advance.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Sun, 27 May 2012 21:44:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think so. I guess you could do Master&lt;void&gt;::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&#39;t need the rest of the class, it shouldn&#39;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&#39;s not exactly optimal.</p><p>[EDIT]</p><p>Actually, don&#39;t do the void thing. It doesn&#39;t work. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Stas B.)</author>
		<pubDate>Sun, 27 May 2012 22:08:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could you try having a class on top of it?
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> MasterParent <span class="k2">{</span>
   public:
     <span class="k1">static</span> <span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_TYPE"><span class="a">ALLEGRO_EVENT_TYPE</span></a> STATIC_MEMBER<span class="k2">;</span>
<span class="k2">}</span>

<span class="k1">template</span><span class="k3">&lt;</span><span class="k1">typename</span> T&gt;
<span class="k1">class</span> Master<span class="k3">&lt;</span>T&gt; <span class="k2">:</span> <span class="k1">public</span> MasterParent <span class="k2">{</span>
   <span class="c">//rest of your class that does use the template</span>
<span class="k2">}</span>
</pre></div></div><p>

(this is just a guess...)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Sun, 27 May 2012 22:29:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hahahahaha <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /><br />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 <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><br />Also, I&#39;ve found this method that gave no errors<span class="ref"><sup>[<a href="#">1</a>]</sup></span>
</p><div class="source-code"><div class="toolbar"><span class="name">implementation.hpp</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#include "master.hpp"</span>
<span class="number">  2</span>
<span class="number">  3</span><span class="c">//Forward declaration</span>
<span class="number">  4</span><span class="k1">class</span> unknown<span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="k1">void</span> check_event<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_TYPE"><span class="a">ALLEGRO_EVENT_TYPE</span></a> x<span class="k2">)</span><span class="k2">{</span>
<span class="number">  7</span>  <span class="k1">if</span><span class="k2">(</span>x<span class="k3">=</span><span class="k3">=</span>Master<span class="k3">&lt;</span>unknown&gt;::STATIC_MEMBER<span class="k2">)</span> <span class="c">//Compiler needs no further information to resolve this</span>
<span class="number">  8</span>    zomfg<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>  <span class="k1">else</span>
<span class="number"> 10</span>    rofl<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span><span class="k2">}</span>
</div></div><p>
J-Gamer, I have considered that option, but I would consider that more of a work-around. Luckily I&#39;ve found this.<br />Stas, and J-Gamer thanks for trying. Here&#39;s some of my fails, for laughs: <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//(1</span>
<span class="k1">template</span> Master::STATIC_MEMBER<span class="k2">;</span>
<span class="c">//(2</span>
Master<span class="k3">&lt;</span>...<span class="k3">&gt;</span><span class="k2">:</span><span class="k2">:</span>STATIC_MEMBER<span class="k2">;</span>
</pre></div></div><p>
</p><div class="ref-block"><h2>References</h2><ol><li>I haven&#39;t done linking yet, but I believe this is one of those cases for which C++&#39;s advanced name mangling was invented. And obviously you need to instantiate the template /somewhere/.</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Sun, 27 May 2012 22:56:39 +0000</pubDate>
	</item>
</rss>
