C
Christopher Pisz
What are one's options when the code one is working on contains a
circular dependency and one is trying to update it to use a shared_ptr
vs a raw pointer?
I don't think I can easily get rid of the preexisting circular
dependency. The original author has created an inheritance where the
base needs the derived. We all know this is wrong, but it would take
quite a bit to analyze how it is used and be removed.
Am I out of luck?
Fictitious Example (best minimal example including the problems the
preexisting code has):
// File MasterClient.h
#include "BaseClient.h"
#include <set>
class MasterClient : BaseClient
{
public:
// Constructor adds this to the collection of clients
// It is later included in the processing of all clients
MasterClient();
// SNIP
private:
typedef std::set<Base *> Clients;
Clients clients_;
// Thread function that iterates over all clients
// including this instance and makes calls on them
void Process();
};
// file BaseClient.h
class MasterClient;
class BaseClient
{
public:
// Constructor
BaseClient(MasterClient * master);
// SNIP interface
private:
MasterClient * master_; // I really need this to be a shared_ptr
// Thread function that makes calls to the MasterClient
virtual void Process();
};
circular dependency and one is trying to update it to use a shared_ptr
vs a raw pointer?
I don't think I can easily get rid of the preexisting circular
dependency. The original author has created an inheritance where the
base needs the derived. We all know this is wrong, but it would take
quite a bit to analyze how it is used and be removed.
Am I out of luck?
Fictitious Example (best minimal example including the problems the
preexisting code has):
// File MasterClient.h
#include "BaseClient.h"
#include <set>
class MasterClient : BaseClient
{
public:
// Constructor adds this to the collection of clients
// It is later included in the processing of all clients
MasterClient();
// SNIP
private:
typedef std::set<Base *> Clients;
Clients clients_;
// Thread function that iterates over all clients
// including this instance and makes calls on them
void Process();
};
// file BaseClient.h
class MasterClient;
class BaseClient
{
public:
// Constructor
BaseClient(MasterClient * master);
// SNIP interface
private:
MasterClient * master_; // I really need this to be a shared_ptr
// Thread function that makes calls to the MasterClient
virtual void Process();
};