0
私はmakeを実行するとき、これらのエラーを得続ける:ここGoogleMockはモッククラスでデストラクタを実装できますか?
debug/main.o: In function `MockMQAdapter<SomeClass>::MockMQAdapter()':
/source/Tests/testsfoo/MockMQAdapter.h:30: undefined reference to `MQAdapter<SomeClass>::~MQAdapter()'
debug/main.o:(.rodata._ZTVN2TW9MQAdapterI6ThingyEE[_ZTVN2TW9MQAdapterI6ThingyEE]+0x10): undefined reference to MQAdapter<SomeClass>::~MQAdapter()'
debug/main.o:(.rodata._ZTVN2TW9MQAdapterI6ThingyEE[_ZTVN2TW9MQAdapterI6ThingyEE]+0x18): undefined reference to `MQAdapter<SomeClass>::~MQAdapter()'
debug/main.o:(.rodata._ZTVN2TW9MQAdapterI6ThingyEE[_ZTVN2TW9MQAdapterI6ThingyEE]+0x20): undefined reference to `MQAdapter<SomeClass>::publish(std::string const&, std::string &message)'
は私のコードです:
#include <gmock/gmock.h>
template<typename S>
class MQAdapter {
public:
MQAdapter(const std::string host, uint16_t port);
virtual ~MQAdapter();
virtual void publish(const std::string queue, std::string message);
};
MQAdapter::MQAdapter(const std::string host, uint16_t port) {}
//Generated by gmock_gen.py
template <typename T0>
class MockMQAdapter : public MQAdapter<T0> {
public:
MOCK_METHOD2_T(publish,
void(std::string, std::string));
};
私はかなり密接にGoogleのモックガイドを追いました。私はこれらのエラーの意味を理解していません。あなたはMQAdapter
デストラクタを宣言し、それを定義していない
TEST(MyTest, ExpectCall) {
MockMQAdapter<SomeClass> *adapter = new MockMQAdapter<SomeClass>("host", 1);
EXPECT_CALL(*adapter, publish("hi", "hello"));
adapter->publish("hi", "hello");
}
最初のコードスニペットと別のコードスニペットが異なる翻訳単位(C++ファイル)にありますか? – Csq
'〜MQAdapter()'を定義していないのはなぜですか? –