【发布时间】:2017-08-31 14:16:32
【问题描述】:
我使用的代码如下,但是 g++ 给我错误。
#include <stdio.h>
#include <memory>
using Func = void (*)(void *p);
class A {
};
class B {
std::unique_ptr<A, Func> b = std::unique_ptr<A, Func>(nullptr, nullptr);
};
int main()
{
}
g++ 错误消息。
test.cc:10:50: error: expected ‘;’ at end of member declaration
std::unique_ptr<A, Func> b = std::unique_ptr<A, Func>(nullptr, nullptr);
^
test.cc:10:50: error: declaration of ‘std::unique_ptr<A, void (*)(void*)> B::Func’ [-fpermissive]
test.cc:4:31: error: changes meaning of ‘Func’ from ‘using Func = void (*)(void*)’ [-fpermissive]
using Func = void (*)(void *p);
^
test.cc:10:54: error: expected unqualified-id before ‘>’ token
std::unique_ptr<A, Func> b = std::unique_ptr<A, Func>(nullptr, nullptr);
^
test.cc:10:47: error: template argument 1 is invalid
std::unique_ptr<A, Func> b = std::unique_ptr<A, Func>(nullptr, nullptr);
^
test.cc:10:47: error: template argument 2 is invalid
g++ 版本
root@ubuntu-linux:~/trafficserver/iocore/net/quic# g++ test.cc -std=c++11^C
root@ubuntu-linux:~/trafficserver/iocore/net/quic# g++ -v
gcc version 4.9.4 (Ubuntu 4.9.4-2ubuntu1~14.04.1)
好像删除功能不好。
【问题讨论】:
-
是的,
nullptr不是有效的删除函数。你期待什么? -
@nwp
nullptr不能用作删除器,但就类型系统而言,它是Func参数的合法值。