4

以下に示すように、コンストラクター宣言(引数付き)を使用して、通常のクラスからテストフィクスチャクラスを作成しようとしています。

hello.h

class hello
{
public:
hello(const uint32_t argID, const uint8_t argCommand);
virtual ~hello();
void initialize();
};

ここで、uint32_tは次のとおりです。uint8_tは次のとおりtypedef unsigned intです。typedef unsigned char

私のテストフィクスチャクラス:

helloTestFixture.h

class helloTestFixture:public testing::Test
{
public:
helloTestFixture(/*How to carry out the constructor declaration in this test fixture class corresponding to the above class?*/);
virtual ~helloTestFixture();
hello m_object;
    };
TEST_F(helloTestFixture, InitializeCheck) // Test to access the 'intialize' function
{
m_object.initialize();
}

上記のコードを実装しようとすると、エラーが発生します。

 Error C2512: no appropriate default constructor available

hello.hファイルで作成されたコンストラクターをhellotestfixture.hファイルに複製しようとしていました。それを行うための方法はありますか?私はそれを多くの方法で実装しようとしましたが、まだ成功していません。これを実装する方法について何か提案はありますか?

4

2 に答える 2

2

あまりコードを修正した後、ここに私が用意したものがあります:答え:)

class hello
{
public:
  hello(const uint32_t argID, const uint8_t argCommand);
virtual ~hello();
void initialize();
};

hello::hello(const uint32_t argID, const uint8_t argCommand){/* do nothing*/}
hello::~hello(){/* do nothing*/}
void hello::initialize(){/* do nothing*/}

class helloTestFixture
{
public:
  helloTestFixture();
  virtual ~helloTestFixture();
  hello m_object;
};

helloTestFixture::helloTestFixture():m_object(0,0){/* do nothing */}
helloTestFixture::~helloTestFixture(){/* do nothing */}

int main()
{
    helloTestFixture htf;
    htf.m_object.initialize();
}

これはうまくコンパイルおよび実行され、これがあなたの質問に答えることを願っています. :)

于 2011-12-02T12:00:31.987 に答える