How to inject mock object?
<p>I am trying to do a unit test to test the DoLogin method:</p>

<pre><code>CLoginActivity::CLoginActivity()
{
    m_pTask = new Task();
}

void CLoginActivity::DoLogin()
{
    m_pTask.execute();
}
</code></pre>

<p>where the Task is another class that I need to mock.</p>

<pre><code>class MockTask : public Task
{
public:
    MOCK_METHOD0(Execute, void());

};
</code></pre>

<p>To inject the <code>MockTask task</code> object, I must change my construction:</p>

<pre><code>CLoginActivity::CLoginActivity(Task&amp; task)
{
    m_pTask = task;
}
</code></pre>

<p>or write a set function:</p>

<pre><code>CLoginActivity::SetTask(Task&amp; task)
{
    m_pTask = task;
}
</code></pre>

<p>Is there other method to inject instead those two methods? And I use gmock in my unit test project.</p>