I’m pretty sure subClassing would defeat the “An interface looks like a class, but has no implementation.” thing, but I’m not sure how else to do this?
I want to use an interface to describe generic behavior for my different Topology classes, and then be able to pass the concrete implementations into another class as the interface type…
So ISOMLatticeTopology.h is implemented by CSOM2DLatticeTopology, CSOM3DLatticeTopology, and CSOM3DLatticeTopology. At run time, I want to be able to pick which Topology I would like, and then the concrete class is passed into my CSOMLatticeSettings class as a type ISOMLatticeTopology (see below).
I tried to thin the code out here just to show one example, but its happening a ton as I’m trying to pass around a bunch of my classes this way. Is there a better way to pass classes? I can do it without making them reference counted. Am I misunderstanding some fundamental thing about reference counting objects?
Additionally, I would like the Objects to be const. However, I keep getting things like /Developer/juce/juce_amalgamated.h:6460: error: passing ‘const ISOMLatticeTopology’ as ‘this’ argument of ‘void juce::ReferenceCountedObject::decReferenceCount()’ discards qualifiers
CSOMMain.h
class CSOMMain
{
public:
//==============================================================================
CSOMMain();
~CSOMMain();
void initSOM();
private:
ReferenceCountedObjectPtr<const ISOMLatticeTopology> m_pSOMTopology;
ReferenceCountedObjectPtr<const CSOMLatticeSettings> m_pLatticeSettings;
};
CSOMMain.cpp
void CSOMMain::initSOM()
{
//create topology
m_pSOMTopology = new CSOM2DLatticeTopology(10,10);
//create the settings
m_pLatticeSettings = new CSOMLatticeSettings(); //make a settings object
m_pLatticeSettings->LatticeTopology( m_pSOMTopology ); //set the topology obj.
}
Here is the interface where I want to subclass ReferenceCountedObject, but I get the error: expected class-name before ‘{’ token
ISOMLatticeTopology.h
class ISOMLatticeTopology : public ReferenceCountedObject
{
public:
ISOMLatticeTopology() {};
virtual double LatticeDistance(long CellIndex1, long CellIndex2) const =0;
// returns a value which represents the topological distance
// between the cells corresponding to passed indicies
// It is the user's responsibility to define the representation
virtual unsigned long NumberOfCells() const =0;
// returns the number of cells necessary for the given
// topology.
virtual ~ISOMLatticeTopology() {};
};
Thanks for any help,
Owen