会员职能的专业化 [英] Specialization of Member functions

查看:51
本文介绍了会员职能的专业化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看下面的代码snippit:

----------------------------- --------------------------

template< class TraitClass = int>

class TestClass

{

public:

void CallFunc()

{

SpecializedFunct_< ; TraitClass>();

}


私人:

模板< class TraitClass>

void SpecializedFunct_(无效)

{

//要求非专业

}


模板<>

void SpecializedFunct_< int>(void)

{

//专门针对TraitClass = int

}


模板<>

void SpecializedFunct_< char>(无效)

{

//专门针对TraitClass = char

}

};

------------- ------------------------------------------


它适用于Visual Studio .NET 2003。与<。抱怨高天堂br />
Red Hat Linux 9.0附带的gcc 3.2.2编译器。


我已经做了一些挖掘,并在我的google-mining中发现了一些模糊

说明了不支持

非专业类的成员函数的特化。


所以我有2个问题:


1.标准是否已更改且MS是否在球上,或者是MS编译器

扩展名允许此项工作?


2.非常感谢有关如何解决这个问题的建议,我非常希望有专门的会员功能。


thanx!

解决方案

Patrick Kutch写道:

请看下面的代码snippit :
--------------------------------------------- ----------
模板< class TraitClass = int>
类TestClass
{
公开:
void CallFun c()
{
SpecializedFunct_< TraitClass>();
}

私人:
模板< class TraitClass>
void SpecializedFunct_ (无效)
//要求非专业化


模板<>
void SpecializedFunct_< int>(void)
{
//专门用于TraitClass = int
}

模板<>
void SpecializedFunct_< char>(void)
{
//专门用于TraitClass = char
}
};
-------------------------- -----------------------------

它适用于Visual Studio .NET 2003.抱怨很高-heaven与Red Hat Linux 9.0附带的gcc 3.2.2编译器。

我已经做了一些挖掘,并在我的谷歌挖掘中发现了一些问题
说不支持
非专业类的成员函数专业化的效果。

所以我有2个阙注意:

1.标准是否已更改且MS是否在球上,或者它是否为MS编译器延伸,可以使其正常工作?

2。非常感谢有关如何解决这个问题的建议,我真的很想拥有专门的会员功能。

thanx!




这对你有用吗?

模板< class TraitClass = int>

class TestClass

{

public:

void CallFunc()

{

SpecializedFunct_();

}


私人:

void SpecializedFunct_()

{

//要求非专业化

}

};


模板<>

void

TestClass< int> ; :: SpecializedFunct_(void)

{

//专门针对TraitClass = int

}


template<>

void

TestClass< char> :: SpecializedFunct_(void)

{

//专门针对TraitClass = char

}

-Slawomir Lisznianski



" Patrick Kutch" <帕***** @ dsl-only.net>在消息中写道

news:40 ******** @ nntp0.pdx.net ...

请看下面的代码snippit:
----------------------------------------------- --------
模板< class TraitClass = int>
类TestClass
{
公开:
void CallFunc()
{
SpecializedFunct_< TraitClass>();
}

私人:
模板< class TraitClass>
void SpecializedFunct_(void)
{<



模板<>
void SpecializedFunct_< int>(void)

//专门用于TraitClass = int
}

模板<>
void SpecializedFunct_< char>(void)
//专门用于TraitClass = char
}
};
----------------------------------- --------------------

它适用于Visual Studio .NET 2003.抱怨高h使用随Red Hat Linux 9.0附带的gcc 3.2.2编译器。

我已经做了一些挖掘,并在我的谷歌挖掘中找到了一些简介
说了些什么不支持
非专业课成员职能的专业化。

所以我有2个问题:

1.标准是否已更改和MS在球上,或者它是一个MS编译器延伸,允许这个工作?


我会信赖gcc。我不认为明确的专业化

应该适用于你的情况。

2.非常感谢有关如何解决这个问题的建议,我确实我真的很想拥有专门的会员功能。




Slawomir提出了一个可以为你服务的解决方案。

他专门研究课程而不是会员功能(好看的方式

不同的东西;-))

祝福,

Sharad




" Slawomir Lisznianski" < SL ********** @ asyncnet.com>在留言中写道

news:b5 ******************** @ dls.net ...

Patrick Kutch写道:

请看下面的代码snippit:
------------------------- ------------------------------
template< class TraitClass = int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_< TraitClass>();
}

私人: template< class TraitClass>
void SpecializedFunct_(void)
//
//要求非专业化


模板<>
void SpecializedFunct_< int>(void)
//专门用于TraitClass = int
}

模板<>
void SpecializedFunct_< ; char>(void)
{
}
};
------------- ------------------------------------------

好吧使用Visual Studio .NET 2003很高兴。使用Red Hat Linux 9.0附带的gcc 3.2.2编译器向高天堂
抱怨。

我做了一些挖掘,发现了一些在我的google-mining中搞砸了
说明不支持
a非专业类的成员函数的专业化。

所以我有2个问题:

1.标准是否已更改且MS是否在球上,或者它是否为MS
编译器扩展允许此操作?

2.非常感谢建议关于如何解决这个
问题,我真的很想拥有专门的会员功能。

thanx!



这会对你有用吗?

模板< class TraitClass = int>
类TestClass
{
公开:
void CallFunc()
{
SpecializedFunct_();
}
私人:
void SpecializedFunct_()
//呼叫非专业的
}
};

模板<>
void
TestClass< int> :: SpecializedFunct_(void)
{
//专门用于TraitClass = int
}

模板<>
void
TestClass< char> :: SpecializedFunct_(void)
{
//专门针对TraitClass = char
}

-Slawomir Lisznianski



我不是相信如此。这个例子很简单,我的实际课程有6个模板

参数 - 很难专门化所有这些参数。


- Patrick


Please take a look at the following code snippit:
-------------------------------------------------------
template<class TraitClass=int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_<TraitClass>();
}

private:
template<class TraitClass >
void SpecializedFunct_(void)
{
// called for non-specialized
}

template<>
void SpecializedFunct_<int>(void)
{
// specialized for TraitClass=int
}

template<>
void SpecializedFunct_<char>(void)
{
// specialized for TraitClass=char
}
};
-------------------------------------------------------

It works GREAT with Visual Studio .NET 2003. Complains to high-heaven with
the gcc 3.2.2 compiler that came with Red Hat Linux 9.0.

I have done some digging and found a few blurbs in my google-mining that
says something to the effect that specialization of member functions for a
non-specialized class is not supported.

So I have 2 questions:

1. Has the standard changed and MS is on the ball, or is it a MS compiler
extension that allows this to work?

2. Would greatly appreciate suggestions on how to get around this issue, I
really really would like to have specialized member functions.

thanx!

解决方案

Patrick Kutch wrote:

Please take a look at the following code snippit:
-------------------------------------------------------
template<class TraitClass=int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_<TraitClass>();
}

private:
template<class TraitClass >
void SpecializedFunct_(void)
{
// called for non-specialized
}

template<>
void SpecializedFunct_<int>(void)
{
// specialized for TraitClass=int
}

template<>
void SpecializedFunct_<char>(void)
{
// specialized for TraitClass=char
}
};
-------------------------------------------------------

It works GREAT with Visual Studio .NET 2003. Complains to high-heaven with
the gcc 3.2.2 compiler that came with Red Hat Linux 9.0.

I have done some digging and found a few blurbs in my google-mining that
says something to the effect that specialization of member functions for a
non-specialized class is not supported.

So I have 2 questions:

1. Has the standard changed and MS is on the ball, or is it a MS compiler
extension that allows this to work?

2. Would greatly appreciate suggestions on how to get around this issue, I
really really would like to have specialized member functions.

thanx!



Would this work for you?
template<class TraitClass=int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_();
}

private:
void SpecializedFunct_()
{
// called for non-specialized
}
};

template<>
void
TestClass<int>::SpecializedFunct_(void)
{
// specialized for TraitClass=int
}

template<>
void
TestClass<char>::SpecializedFunct_(void)
{
// specialized for TraitClass=char
}
-Slawomir Lisznianski



"Patrick Kutch" <Pa*****@dsl-only.net> wrote in message
news:40********@nntp0.pdx.net...

Please take a look at the following code snippit:
-------------------------------------------------------
template<class TraitClass=int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_<TraitClass>();
}

private:
template<class TraitClass >
void SpecializedFunct_(void)
{
// called for non-specialized
}

template<>
void SpecializedFunct_<int>(void)
{
// specialized for TraitClass=int
}

template<>
void SpecializedFunct_<char>(void)
{
// specialized for TraitClass=char
}
};
-------------------------------------------------------

It works GREAT with Visual Studio .NET 2003. Complains to high-heaven with
the gcc 3.2.2 compiler that came with Red Hat Linux 9.0.

I have done some digging and found a few blurbs in my google-mining that
says something to the effect that specialization of member functions for a
non-specialized class is not supported.

So I have 2 questions:

1. Has the standard changed and MS is on the ball, or is it a MS compiler
extension that allows this to work?
I would place my trust with gcc here. I don''t think explicit specialization
should work in your case.
2. Would greatly appreciate suggestions on how to get around this issue, I
really really would like to have specialized member functions.



Slawomir has suggested a solution which could work for you.
He specializes the class rather than the member function (Nice way to look at
things differently ;-))

Best wishes,
Sharad



"Slawomir Lisznianski" <sl**********@asyncnet.com> wrote in message
news:b5********************@dls.net...

Patrick Kutch wrote:

Please take a look at the following code snippit:
-------------------------------------------------------
template<class TraitClass=int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_<TraitClass>();
}

private:
template<class TraitClass >
void SpecializedFunct_(void)
{
// called for non-specialized
}

template<>
void SpecializedFunct_<int>(void)
{
// specialized for TraitClass=int
}

template<>
void SpecializedFunct_<char>(void)
{
// specialized for TraitClass=char
}
};
-------------------------------------------------------

It works GREAT with Visual Studio .NET 2003. Complains to high-heaven with the gcc 3.2.2 compiler that came with Red Hat Linux 9.0.

I have done some digging and found a few blurbs in my google-mining that
says something to the effect that specialization of member functions for a non-specialized class is not supported.

So I have 2 questions:

1. Has the standard changed and MS is on the ball, or is it a MS compiler extension that allows this to work?

2. Would greatly appreciate suggestions on how to get around this issue, I really really would like to have specialized member functions.

thanx!



Would this work for you?
template<class TraitClass=int>
class TestClass
{
public:
void CallFunc()
{
SpecializedFunct_();
}

private:
void SpecializedFunct_()
{
// called for non-specialized
}
};

template<>
void
TestClass<int>::SpecializedFunct_(void)
{
// specialized for TraitClass=int
}

template<>
void
TestClass<char>::SpecializedFunct_(void)
{
// specialized for TraitClass=char
}
-Slawomir Lisznianski


I don''t believe so. The example is trivial, my actual class has 6 template
parameters - would be rather difficult to specialize all of them.

- Patrick


这篇关于会员职能的专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆