任何函数都可以被删除的函数? [英] Can any function be a deleted-function?
本文介绍了任何函数都可以被删除的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
工作草案明确调用 defaulted-functions 必须是特殊成员函数(例如,copy-constructor,default-constructor等,§8.4.2.1-1)。
The working draft explicitly calls out that defaulted-functions must be special member functions (eg copy-constructor, default-constructor, etc, (§8.4.2.1-1)). Which makes perfect sense.
但是,我没有在 deleted-functions (§8.4.3)中看到任何这样的限制。是这样吗?
However, I don't see any such restriction on deleted-functions(§8.4.3). Is that right?
或者换句话说,这三个例子有效 c ++ 0
?
Or in other words are these three examples valid c++0
?
struct Foo
{
// 1
int bar( int ) = delete;
};
// 2
int baz( int ) = delete;
template< typename T >
int boo( T t );
// 3
template<>
int boo<int>(int t) = delete;
推荐答案
C ++ 0x spec(& .fct.def.delete])不拒绝这样的结构,而g ++ 4.5识别所有这3个。
The C++0x spec (§[dcl.fct.def.delete]) doesn't deny such constructs, and g++ 4.5 recognize all 3 of them.
x.cpp: In function 'int main()':
x.cpp:4:8: error: deleted function 'int Foo::bar(int)'
x.cpp:21:11: error: used here
x.cpp:9:5: error: deleted function 'int baz(int)'
x.cpp:22:2: error: used here
x.cpp:9:5: error: deleted function 'int baz(int)'
x.cpp:22:8: error: used here
x.cpp:17:5: error: deleted function 'int boo(T) [with T = int]'
x.cpp:23:7: error: used here
这篇关于任何函数都可以被删除的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文