<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 14.5 &#8212; Class template specialization</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/</link>
	<description></description>
	<lastBuildDate>Wed, 08 Sep 2010 10:51:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Abhishek</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-83561</link>
		<dc:creator>Abhishek</dc:creator>
		<pubDate>Sun, 25 Apr 2010 07:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-83561</guid>
		<description>Hi Alex,

Why is it so that for creating function template specialization we don&#039;t need to have template&lt;&gt; keyword 
Like you have explained in previous tutorial :
&lt;pre&gt; 
void Storage&lt;double&gt;::Print()
{
std::cout &lt;&lt; std::scientific &lt;&lt; m_tValue &lt;&lt; std::endl;
}
&lt;!--formatted--&gt;&lt;/pre&gt;

But for class template specialization we need the template &lt;&gt; keyword 
&lt;pre&gt;
template &lt;&gt;
class Storage8&lt;bool&gt; 
{ ...};
&lt;!--formatted--&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi Alex,</p>
<p>Why is it so that for creating function template specialization we don&#8217;t need to have template&lt;&gt; keyword<br />
Like you have explained in previous tutorial :</p>
<pre>
void Storage&lt;double&gt;::Print()
{
std::cout &lt;&lt; std::scientific &lt;&lt; m_tValue &lt;&lt; std::endl;
}
<!--formatted--></pre>
<p>But for class template specialization we need the template &lt;&gt; keyword </p>
<pre>
template &lt;&gt;
class Storage8&lt;bool&gt;
{ ...};
<!--formatted--></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Backton</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-69478</link>
		<dc:creator>Tom Backton</dc:creator>
		<pubDate>Thu, 01 Oct 2009 18:44:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-69478</guid>
		<description>**************Please ignore the previous comment...I forgot the tags...*******
******************************************************************************

Few questions...
1. Can I specialize a class template&#039;s member function? For example, let&#039;s say I have a class template like this: 

&lt;pre&gt;template&lt;class A, class B, class C&gt; MyClass;&lt;/pre&gt;

For B=int, some member functions need to have special implementations. Can I define 
&lt;pre&gt;template&lt;class A, class B, class C&gt; void MyClass&lt;A,B,C&gt;::func() {...}&lt;/pre&gt;

and then just define a special implementation like this:

&lt;pre&gt;template&lt;class A, class C&gt; void MyClass&lt;A,int,C&gt;::func() {...}&lt;/pre&gt;

It it possible?

2. MyClass&#039;s functions have few different implementations. And the interface is different too. One method is defining each version as a different class, but what if I&#039;d like to use a template instead? in template, impl is the implementation&#039;s number. Can I define a general class definition:

&lt;pre&gt;template&lt;class A, class B, int impl&gt; class MyClass { ... };&lt;/pre&gt;

And then define a specialization for impl=1 like this:

&lt;pre&gt;template&lt;class A, class B&gt; class MyClass&lt;A,B,1&gt; { ... };&lt;/pre&gt;

Is it possible?

3. If yes, let&#039;s say MyClass is a template like this:
&lt;pre&gt;template&lt;class A, class B, class C&gt; class MyClass { ... };&lt;/pre&gt;

For A=int, I&#039;d like to specialize this class template:
&lt;pre&gt;template&lt;class B, class C&gt; class MyClass&lt;int,B,C&gt; { ... };&lt;/pre&gt;

For A=int and C=double, I&#039;d like to have another specialization:  (but for A=int and C!=double I&#039;d like the compiler to use the first specialization)
&lt;pre&gt;template&lt;class B&gt; class MyClass&lt;int,B,double&gt; { ... };&lt;/pre&gt;

And I&#039;d also like to have a full specialization like this:
&lt;pre&gt;template&lt;&gt; class MyClass&lt;int,char*,double&gt; { ... };&lt;/pre&gt;

Do compilers ready to handle such sets of specializations?</description>
		<content:encoded><![CDATA[<p>**************Please ignore the previous comment&#8230;I forgot the tags&#8230;*******<br />
******************************************************************************</p>
<p>Few questions&#8230;<br />
1. Can I specialize a class template&#8217;s member function? For example, let&#8217;s say I have a class template like this: </p>
<pre>template&lt;class A, class B, class C&gt; MyClass;</pre>
<p>For B=int, some member functions need to have special implementations. Can I define </p>
<pre>template&lt;class A, class B, class C&gt; void MyClass&lt;A,B,C&gt;::func() {...}</pre>
<p>and then just define a special implementation like this:</p>
<pre>template&lt;class A, class C&gt; void MyClass&lt;A,int,C&gt;::func() {...}</pre>
<p>It it possible?</p>
<p>2. MyClass&#8217;s functions have few different implementations. And the interface is different too. One method is defining each version as a different class, but what if I&#8217;d like to use a template instead? in template, impl is the implementation&#8217;s number. Can I define a general class definition:</p>
<pre>template&lt;class A, class B, int impl&gt; class MyClass { ... };</pre>
<p>And then define a specialization for impl=1 like this:</p>
<pre>template&lt;class A, class B&gt; class MyClass&lt;A,B,1&gt; { ... };</pre>
<p>Is it possible?</p>
<p>3. If yes, let&#8217;s say MyClass is a template like this:</p>
<pre>template&lt;class A, class B, class C&gt; class MyClass { ... };</pre>
<p>For A=int, I&#8217;d like to specialize this class template:</p>
<pre>template&lt;class B, class C&gt; class MyClass&lt;int,B,C&gt; { ... };</pre>
<p>For A=int and C=double, I&#8217;d like to have another specialization:  (but for A=int and C!=double I&#8217;d like the compiler to use the first specialization)</p>
<pre>template&lt;class B&gt; class MyClass&lt;int,B,double&gt; { ... };</pre>
<p>And I&#8217;d also like to have a full specialization like this:</p>
<pre>template&lt;&gt; class MyClass&lt;int,char*,double&gt; { ... };</pre>
<p>Do compilers ready to handle such sets of specializations?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Backton</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-69477</link>
		<dc:creator>Tom Backton</dc:creator>
		<pubDate>Thu, 01 Oct 2009 18:35:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-69477</guid>
		<description>Few questions...
1. Can I specialize a class template&#039;s member function? For example, let&#039;s say I have a class template like this: 

template MyClass;

For B=int, some member functions need to have special implementations. Can I define 
template void MyClass&lt;A&gt;::func() {...}

and them just define a special implementation like this:

template void MyClass&lt;A&gt;::func() {...}

It it possible?

2. MyClass&#039;s functions have few different implementations. And the interface is different too. One method is defining each version as a different class, but what if I&#039;d like to use a template instead? in template, impl is the implementation&#039;s number. Can I define a general class definition:

template class MyClass { ... };

And then define a specialization for impl=1 like this:

template class MyClass&lt;A&gt; { ... };

Is it possible?

3. If yes, let&#039;s say MyClass is a template like this:
template class MyClass { ... };

For A=int, I&#039;d like to specialize this class template:
template class MyClass { ... };

For A=int and C=double, I&#039;d like to have another specialization:  (but for A=int and C!=double I&#039;d like the compiler to use the first specialization)
template class MyClass { ... };

And I&#039;d also like to have a full specialization for :
template class MyClass { ... };

Do compilers ready to handle such sets of specializations?</description>
		<content:encoded><![CDATA[<p>Few questions&#8230;<br />
1. Can I specialize a class template&#8217;s member function? For example, let&#8217;s say I have a class template like this: </p>
<p>template MyClass;</p>
<p>For B=int, some member functions need to have special implementations. Can I define<br />
template void MyClass<a>::func() {&#8230;}</p>
<p>and them just define a special implementation like this:</p>
<p>template void MyClass</a><a>::func() {&#8230;}</p>
<p>It it possible?</p>
<p>2. MyClass&#8217;s functions have few different implementations. And the interface is different too. One method is defining each version as a different class, but what if I&#8217;d like to use a template instead? in template, impl is the implementation&#8217;s number. Can I define a general class definition:</p>
<p>template class MyClass { &#8230; };</p>
<p>And then define a specialization for impl=1 like this:</p>
<p>template class MyClass</a><a> { &#8230; };</p>
<p>Is it possible?</p>
<p>3. If yes, let&#8217;s say MyClass is a template like this:<br />
template class MyClass { &#8230; };</p>
<p>For A=int, I&#8217;d like to specialize this class template:<br />
template class MyClass { &#8230; };</p>
<p>For A=int and C=double, I&#8217;d like to have another specialization:  (but for A=int and C!=double I&#8217;d like the compiler to use the first specialization)<br />
template class MyClass { &#8230; };</p>
<p>And I&#8217;d also like to have a full specialization for :<br />
template class MyClass { &#8230; };</p>
<p>Do compilers ready to handle such sets of specializations?</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-59729</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 02 May 2009 03:53:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-59729</guid>
		<description>cIntStorage[nCount] will work if operator[] has been overridden for the Storage8 class.

Similarly, ob[i] will work if operator[] has been overridden for class A.</description>
		<content:encoded><![CDATA[<p>cIntStorage[nCount] will work if operator[] has been overridden for the Storage8 class.</p>
<p>Similarly, ob[i] will work if operator[] has been overridden for class A.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Memory the Hedgehog</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-52708</link>
		<dc:creator>Memory the Hedgehog</dc:creator>
		<pubDate>Mon, 23 Mar 2009 21:40:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-52708</guid>
		<description>About 5 paragraphs above the go to next/previous page buttons, you forgot a semicolon on the html entity &amp; gt ;, writing &amp;gt, in the following:

..while C++ gives us free reign to add, remove, or change functions of Storage8&lt;b&gt;&lt;bool&amp;gt&lt;/b&gt; as we see fit, keeping a consistent..

[ Fixed.  Thanks for noticing.  -Alex ]</description>
		<content:encoded><![CDATA[<p>About 5 paragraphs above the go to next/previous page buttons, you forgot a semicolon on the html entity &amp; gt ;, writing &amp;gt, in the following:</p>
<p>..while C++ gives us free reign to add, remove, or change functions of Storage8<b>&lt;bool&amp;gt</b> as we see fit, keeping a consistent..</p>
<p>[ Fixed.  Thanks for noticing.  -Alex ]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nedu</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-51812</link>
		<dc:creator>Nedu</dc:creator>
		<pubDate>Fri, 20 Mar 2009 07:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-51812</guid>
		<description>&lt;pre&gt;
Hi,
I am really enjoying this readings.
i have a clarification here.

04     Storage8&lt;int&gt; cIntStorage;  
05   
06     for (int nCount=0; nCount&lt;8; nCount++)  
07         cIntStorage[nCount] = nCount; 

look at lines 04 &amp; 07
 Is this legal to the compiler ?
 if so why the following gives compiler error.


class A
{
     public:
        int data;
};


int main()
{

  A ob;
        for(int i=0;i&lt;10;i++)
        ob[i]=i;

        for(int i=0;i&lt;10;i++)
        cout&lt;&lt;endl&lt;&lt;ob[i]&lt;&lt;endl;

  return 0;

}



&lt;!--formatted--&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
Hi,
I am really enjoying this readings.
i have a clarification here.

04     Storage8&lt;int&gt; cIntStorage;
05
06     for (int nCount=0; nCount&lt;8; nCount++)
07         cIntStorage[nCount] = nCount; 

look at lines 04 &amp; 07
 Is this legal to the compiler ?
 if so why the following gives compiler error.

class A
{
     public:
        int data;
};

int main()
{

  A ob;
        for(int i=0;i&lt;10;i++)
        ob[i]=i;

        for(int i=0;i&lt;10;i++)
        cout&lt;&lt;endl&lt;&lt;ob[i]&lt;&lt;endl;

  return 0;

}

<!--formatted--></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 14.6 &#8212; Partial template specialization</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-29123</link>
		<dc:creator>Learn C++ - &#187; 14.6 &#8212; Partial template specialization</dc:creator>
		<pubDate>Sat, 04 Oct 2008 21:27:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-29123</guid>
		<description>[...] 14.5 &#8212; Class template specialization  [...]</description>
		<content:encoded><![CDATA[<p>[...] 14.5 &#8212; Class template specialization  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-28043</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sun, 21 Sep 2008 17:31:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-28043</guid>
		<description>I just realized I made a mistake in my code and flipped the true/false results.  That&#039;s been fixed, so take another look now.  nCount &amp; 3 produces an integer value.  C++ will implicitly cast the result of this expression to an boolean.  If the result is 0, the boolean will be false.  If the result is non-zero, the boolean will be true.  So when is nCount &amp; 3 == 0?  When nCount is a number that has it&#039;s first and second bits set to 0 (in other words, 0, 4, 8, 12, ...).  Consequently, when nCount is one of these numbers, nCount &amp; 3 will be zero, and the boolean will be set to false.  When nCount is not one of these numbers, nCount &amp; 3 will be non-zero, which means the boolean will be set to true.</description>
		<content:encoded><![CDATA[<p>I just realized I made a mistake in my code and flipped the true/false results.  That&#8217;s been fixed, so take another look now.  nCount &#038; 3 produces an integer value.  C++ will implicitly cast the result of this expression to an boolean.  If the result is 0, the boolean will be false.  If the result is non-zero, the boolean will be true.  So when is nCount &#038; 3 == 0?  When nCount is a number that has it&#8217;s first and second bits set to 0 (in other words, 0, 4, 8, 12, &#8230;).  Consequently, when nCount is one of these numbers, nCount &#038; 3 will be zero, and the boolean will be set to false.  When nCount is not one of these numbers, nCount &#038; 3 will be non-zero, which means the boolean will be set to true.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hasti</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-27096</link>
		<dc:creator>Hasti</dc:creator>
		<pubDate>Fri, 12 Sep 2008 08:07:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-27096</guid>
		<description>Hi,
I don&#039;t understand the meaning of line 15 of the first example in this page(in the main() function), I mean:
       cBoolStorage.Set(nCount, nCount &amp; 3);
I have problem with the second argument of the Set function? Would you please explain it more?(I know it should be a bool, but how could it be?)
Herewith, I would like to thank the writer of this tutorial! I always enjoy reading these pages!</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I don&#8217;t understand the meaning of line 15 of the first example in this page(in the main() function), I mean:<br />
       cBoolStorage.Set(nCount, nCount &amp; 3);<br />
I have problem with the second argument of the Set function? Would you please explain it more?(I know it should be a bool, but how could it be?)<br />
Herewith, I would like to thank the writer of this tutorial! I always enjoy reading these pages!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 14.4 &#8212; Expression parameters and template specialization</title>
		<link>http://www.learncpp.com/cpp-tutorial/145-class-template-specialization/comment-page-1/#comment-23968</link>
		<dc:creator>Learn C++ - &#187; 14.4 &#8212; Expression parameters and template specialization</dc:creator>
		<pubDate>Sat, 16 Aug 2008 22:27:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=210#comment-23968</guid>
		<description>[...] 14.5 &#8212; Class template specialization  [...]</description>
		<content:encoded><![CDATA[<p>[...] 14.5 &#8212; Class template specialization  [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
