相关疑难解决方法(0)

谷歌可以用智能指针返回类型模拟一个方法吗?

我有一个返回智能指针的工厂.无论我使用什么智能指针,我都无法让Google Mock嘲笑工厂方法.

模拟对象是纯抽象接口的实现,其中所有方法都是虚拟的.我有一个原型:

MOCK_METHOD0(Create, std::unique_ptr<IMyObjectThing>());
Run Code Online (Sandbox Code Playgroud)

我得到:

"...gmock/gmock-spec-builders.h(1314): error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'"
Run Code Online (Sandbox Code Playgroud)

定义了智能指针中指向的类型.

我得到它试图访问一个声明私有的构造函数,但我不明白为什么.当这是一个std :: auto_ptr时,错误说没有复制构造函数,这让我很困惑.

无论如何,有没有办法模拟一个返回智能指针的方法?或者有更好的方法来建造工厂吗?我唯一的决心是返回一个原始指针(blech ......)?

我的环境是Visual Studio 2010 Ultimate和Windows 7.我没有使用CLI.

c++ unit-testing smart-pointers googlemock

46
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

googlemock ×1

smart-pointers ×1

unit-testing ×1