def*_*ode 5 c++ deleted-functions c++11
工作草案明确地指出,默认函数必须是特殊的成员函数(例如复制构造函数,默认构造函数等,(§8.4.2.1-1)).这很有道理.
但是,我没有看到对删除函数的任何此类限制(第8.4.3节).是对的吗?
或者换句话说这三个例子是否有效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;
Run Code Online (Sandbox Code Playgroud)
C++0x 规范 (§[dcl.fct.def.delete]) 并不否认此类构造,并且 g++ 4.5 识别所有这 3 个构造。
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
Run Code Online (Sandbox Code Playgroud)