0
审核中

适配器c++用例代码有错误,Adapter *adapter = Adapter(adaptee); 编译失败

ZhAwen 4 lat temu Ostatnio zmodyfikowane przez hustacle 4 lat temu 2

Adapter *adapter = Adapter(adaptee);

是不是应该写成

Adapter adapter = Adapter(adaptee);

审核中

Hi!

Sorry, I'm not a C++ developer, but when I try to compile your version, I get this error:

main.cc:87:11: error: no viable conversion from 'Adapter *' to 'Adapter'
Adapter adapter = new Adapter(adapted);


Any advice? I'm using Apple clang version 12.0.0

+1

我没编过你说的这段代码,不过按我的理解,你可以试试 Adapter adapter(adaptee); 或 Adapter *adapter = new Adapter(adaptee);