工作草案明确指出默认函数 必须是特殊成员函数(例如复制构造函数、默认构造函数等,(§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;
最佳答案
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
关于c++ - 任何函数都可以是删除函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2875333/