class TestGet : public ::testing::Test
{
protected:
TestGet()
: _txHandle(11)
{
_interface.get = mockGet;
}
Interface_T _interface;
Handle_T _txHandle;
DB _db;
};
If I change DB so that it only has the following constructor:
explicit DB(Interface_T& _interface):
_interface(interface)
{
}
Do I now need to declare _db using a std::shared_ptr in my TestGet class, initialising it with _interface in the constructor?
UPDATE:
The issue was that I had:
private:
Interface_T _interface;
in the DB class instead of a reference.
This should work:
It depends, though, whether the constructor of
DBdoes anything non-trivial. As long as it just stores the reference, this should be fine. That is,DBshould look like this:If you need further initialization, you could either add an
init()function toDB, or make an initialization function forInterface_Tthat you can use in the constructor ofTestGet.