Click here to Skip to main content
15,886,199 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC application has encountered a problem and need to close Pin
ganesh.dp5-May-09 20:07
ganesh.dp5-May-09 20:07 
AnswerRe: MFC application has encountered a problem and need to close Pin
Cedric Moonen5-May-09 20:29
Cedric Moonen5-May-09 20:29 
AnswerRe: MFC application has encountered a problem and need to close Pin
_AnsHUMAN_ 5-May-09 21:38
_AnsHUMAN_ 5-May-09 21:38 
AnswerRe: MFC application has encountered a problem and need to close Pin
ThatsAlok5-May-09 23:20
ThatsAlok5-May-09 23:20 
AnswerRe: MFC application has encountered a problem and need to close Pin
Hamid_RT5-May-09 23:28
Hamid_RT5-May-09 23:28 
GeneralRe: MFC application has encountered a problem and need to close Pin
ganesh.dp5-May-09 23:36
ganesh.dp5-May-09 23:36 
AnswerRe: MFC application has encountered a problem and need to close Pin
David Crow6-May-09 3:14
David Crow6-May-09 3:14 
QuestionPartial Specialization of Templated Class Member Function Pin
Jmuulian5-May-09 19:26
Jmuulian5-May-09 19:26 
Hi all. Slightly tricky one here.

I have a template class that has more than one template argument, for example:

<br />
template< class X, int N ><br />
class Foo<br />
{<br />
public: <br />
int GetValue() const;<br />
};<br />


Now, say that I want to specialize GetValue so that it returns, say, 69 for a template argument of N = 5, but returns 42 for all other values of N. For example:

<br />
Foo< char, 3 > foo1;<br />
foo1.GetValue(); // Returns 42.<br />
<br />
Foo< double, 17 > foo2;<br />
foo2.GetValue(); // Returns 42.<br />
<br />
Foo< bool, 5 > foo3;<br />
foo3.GetValue(); // Returns 69.<br />


One way that would work is to specialize the entire class for N = 5 and again for all other values, so as to provide two separate implementations of the class. For example:

<br />
template< class X, int N ><br />
class Foo<br />
{<br />
public:<br />
int GetNumber() const { return 42; }<br />
};<br />
<br />
template< class X ><br />
class Foo< X, 5 ><br />
{<br />
public:<br />
int GetNumber() const { return 69; }<br />
};<br />


But I want to avoid this approach because while it works well for this simple example class with only one function, I am in practice trying to specialize a member function on a much larger class with many functions that would be unchanged by the specialization. Thus, I need a method to specialize only the member function in question, without duplicating the rest of class Foo.

As far as I can determine, specializing the member function only works if it has a single template parameter, like so:

<br />
template< int N ><br />
class Foo<br />
{<br />
public:<br />
int GetNumber() const { return 42; }<br />
};<br />
<br />
template < int N ><br />
int Foo< N >::GetNumber() const { return 42; }<br />
<br />
template < ><br />
int Foo< 5 >::GetNumber() const { return 69; }<br />


Can anyone explain how I can apply this logic to the case of multiple template arguments? The following code, by way of example, does not compile.
<br />
template< class X, int N ><br />
class Foo<br />
{<br />
public:<br />
int GetNumber() const { return 42; }<br />
};<br />
<br />
template < class X, int N ><br />
int Foo< X, N >::GetNumber() const { return 42; }<br />
<br />
template < class X ><br />
int Foo< X, 5 >::GetNumber() const { return 69; }<br />


Any help would be greatly appreciated.
AnswerRe: Partial Specialization of Templated Class Member Function Pin
«_Superman_»5-May-09 20:04
professional«_Superman_»5-May-09 20:04 
AnswerRe: Partial Specialization of Templated Class Member Function Pin
Stuart Dootson6-May-09 2:14
professionalStuart Dootson6-May-09 2:14 
QuestionOpening a Visual Studio .NET application in Visual Studio C++ Pin
SivaGK5-May-09 19:26
SivaGK5-May-09 19:26 
AnswerRe: Opening a Visual Studio .NET application in Visual Studio C++ Pin
«_Superman_»5-May-09 19:29
professional«_Superman_»5-May-09 19:29 
AnswerRe: Opening a Visual Studio .NET application in Visual Studio C++ Pin
_AnsHUMAN_ 5-May-09 19:47
_AnsHUMAN_ 5-May-09 19:47 
QuestionOne doubt Pin
Deepu Antony5-May-09 19:12
Deepu Antony5-May-09 19:12 
AnswerRe: One doubt Pin
«_Superman_»5-May-09 19:27
professional«_Superman_»5-May-09 19:27 
GeneralRe: One doubt Pin
Deepu Antony5-May-09 19:47
Deepu Antony5-May-09 19:47 
GeneralRe: One doubt Pin
«_Superman_»5-May-09 19:53
professional«_Superman_»5-May-09 19:53 
GeneralRe: One doubt Pin
Deepu Antony5-May-09 20:11
Deepu Antony5-May-09 20:11 
AnswerRe: One doubt Pin
Taran95-May-09 21:35
Taran95-May-09 21:35 
AnswerRe: One doubt Pin
KarstenK5-May-09 23:16
mveKarstenK5-May-09 23:16 
AnswerRe: One doubt Pin
Stuart Dootson6-May-09 2:16
professionalStuart Dootson6-May-09 2:16 
AnswerRe: One doubt Pin
David Crow6-May-09 3:15
David Crow6-May-09 3:15 
Questionin CExplorer1 class, how to post your form data to the server,as login data. Pin
cwj_5-May-09 16:20
cwj_5-May-09 16:20 
AnswerRe: in CExplorer1 class, how to post your form data to the server,as login data. Pin
Madhu Nair5-May-09 18:59
Madhu Nair5-May-09 18:59 
QuestionWhen IS CFont create for the Bottomless CRichEdit ???? Pin
ForNow5-May-09 13:28
ForNow5-May-09 13:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.