2016-04-15 11 views
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"); 
} 
+0

最初のコードスニペットと別のコードスニペットが異なる翻訳単位(C++ファイル)にありますか? – Csq

+0

'〜MQAdapter()'を定義していないのはなぜですか? –

答えて

1

:ここでは私のテストは次のようになります。したがって、リンカーはそれを解決しようとすると文句を言います。定義を提供すると、defaultで十分です。つまり、virtual ~MQAdapter() = default;です。

一方、コンストラクタの定義は、テンプレートパラメータを持つインラインまたは修飾する必要があります:

template <typename S> 
MQAdapter<S>::MQAdapter(const std::string host, uint16_t port) {} 

私はそれは単なる一例だからだと思いますが、あなたがMQAdapterテンプレートパラメータを使用していません何か、それは通常のクラスになる可能性があります。

関連する問題