像往常一样坚持部分特化语法。 [英] Stuck on partial specialization syntax, as usual.
问题描述
我似乎永远无法做到这一点。这里我有一些代码:
模板< typename T,int Nclass A {
void f(T);
};
模板< typename Tvoid A< T,1> :: f(T){
}
模板< typename Tvoid A< T,3> :: f(T){
}
该代码的目标是部分将A< T,N> :: f()专门用于
N的某些值,使T不受约束。语法是我可以从这个站点获取的$ b / b:
http://www.cprogramming.com/tutorial...alization.html
此代码无法编译。 Comeau(使用默认的
设置,当你去试驾网站时)似乎产生了
最清晰的错误:
" ComeauTest.c",第5行:错误:模板参数列表必须与
参数列表匹配
模板< typename Tvoid A< T,1>: :f(T){
" ComeauTest.c",第8行:错误:模板参数列表必须与
参数列表匹配
模板< typename Tvoid A< T,3> :: f(T){
我似乎不能按此编译。什么是正确的语法
这个?
谢谢!
杰森
5月26日凌晨1点12分,jason.cipri ... @ gmail.com
< jason.cipri ... @ gmail .comwrote:
此代码无法编译。 Comeau(使用默认的
设置,当你去试驾网站时)似乎产生了
最清晰的错误:
" ComeauTest.c",第5行:错误:模板参数列表必须与
参数列表匹配
模板< typename Tvoid A< T,1>: :f(T){
" ComeauTest.c",第8行:错误:模板参数列表必须与
参数列表匹配
模板< typename Tvoid A< T,3> :: f(T){
嗯,FWIW这里是GCC所说的(3.4) .5 MinGW):
g ++ pspec.cpp
pspec.cpp:5:错误:无效使用未定义类型` A类< T,1>''
pspec.cpp:1:错误:声明`A类< T,1>''
pspec.cpp:5 :错误:非模板的模板定义`void A< T,
1> :: f(T)''
pspec.cpp:8:错误:无效使用未定义类型`A类< T, 3>''
pspec.cpp:1:错误:声明`A类< T,3>''
pspec.cpp:8:错误:模板定义非模板`void A< T,
3> :: f(T)''
Jason
ja ************ @ gmail.com 写道:
我似乎无法做到这一点。这里我有一些代码:
模板< typename T,int Nclass A {
void f(T);
};
模板< typename Tvoid A< T,1> :: f(T){
}
你不能部分专门化一个班级模板的成员。
-
Ian Collins。
I never seem to be able to get this right. Here I have some code:
template <typename T, int Nclass A {
void f (T);
};
template <typename Tvoid A<T,1>::f (T) {
}
template <typename Tvoid A<T,3>::f (T) {
}
The goal of that code is to partially specialize A<T,N>::f() for
certain values of N, leaving T unconstrained. The syntax is what I
could pick up from this site:
http://www.cprogramming.com/tutorial...alization.html
This code does not compile. Comeau (using whatever the default
settings are when you go to the test drive site) seems to produce the
clearest errors:
"ComeauTest.c", line 5: error: template argument list must match the
parameter list
template <typename Tvoid A<T,1>::f (T) {
"ComeauTest.c", line 8: error: template argument list must match the
parameter list
template <typename Tvoid A<T,3>::f (T) {
I can''t seem to massage this into compiling. What is the right syntax
for this?
Thanks!
Jason
On May 26, 1:12 am, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.comwrote:This code does not compile. Comeau (using whatever the default
settings are when you go to the test drive site) seems to produce the
clearest errors:
"ComeauTest.c", line 5: error: template argument list must match the
parameter list
template <typename Tvoid A<T,1>::f (T) {
"ComeauTest.c", line 8: error: template argument list must match the
parameter list
template <typename Tvoid A<T,3>::f (T) {Well, FWIW here is what GCC says, also (3.4.5 MinGW):
g++ pspec.cpp
pspec.cpp:5: error: invalid use of undefined type `class A<T, 1>''
pspec.cpp:1: error: declaration of `class A<T, 1>''
pspec.cpp:5: error: template definition of non-template `void A<T,
1>::f(T)''
pspec.cpp:8: error: invalid use of undefined type `class A<T, 3>''
pspec.cpp:1: error: declaration of `class A<T, 3>''
pspec.cpp:8: error: template definition of non-template `void A<T,
3>::f(T)''
Jason
ja************@gmail.com wrote:I never seem to be able to get this right. Here I have some code:
template <typename T, int Nclass A {
void f (T);
};
template <typename Tvoid A<T,1>::f (T) {
}
You can''t partially specialise an individual member of class template.
--
Ian Collins.
这篇关于像往常一样坚持部分特化语法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!