F
forums_mp
Consider:
# include<iostream>
# include<vector>
class CBase {
public :
virtual ~CBase() {}
};
class CDerived1 : public CBase {
public :
};
class CDerived2 : public CBase {
public :
};
// etc.
//later
class Worker {
CDerived1 cd1 ;
unsigned int CDerived1Counter ;
bool CDerived1Flag ;
unsigned int CDerived1ID ;
CDerived2 cd2 ;
unsigned int CDerived2Counter ;
bool CDerived2Flag ;
unsigned CDerived2ID ;
/// etc
public :
};
The worker class has a ID, a Flag and a counter for each derived
type. An approach that in my view is just silly. So I decided to
create a repository.
struct Repository {
CBase *ptr;
unsigned int Counter ;
bool Flag ;
unsigned int ID ;
Repository ( CBase *ptr_, int BaseClassID )
: ptr ( ptr_ )
, Counter ( 0 )
, Flag ( false )
, ID ( BaseClassID )
{}
};
typedef std::vector < Repository* > REPOSITORY_VEC ;
class RevisedWorker {
static REPOSITORY_VEC rep_vec ;
public :
RevisedWorker ()
{
rep_vec.push_back ( new Repository ( new CDerived2, 0x400 ) ) ;
rep_vec.push_back ( new Repository ( new CDerived1, 0x300 ) ) ;
// would be nice if i could do.. or perhaps use a map
//rep_vec.add ( new Repository ( new CDerived2, 0x4000 ) )
// .add ( new Repository ( new CDerived1, 0x300 ) ) );
}
};
REPOSITORY_VEC RevisedWorker::rep_vec;
int main() {
RevisedWorker rw;
std::cin.get();
}
At issue: 'new' Repository 'new' CDerivedXX looks unsightey but I'm
not of a reasonable workaround. Ideas? Thanks in advance.
# include<iostream>
# include<vector>
class CBase {
public :
virtual ~CBase() {}
};
class CDerived1 : public CBase {
public :
};
class CDerived2 : public CBase {
public :
};
// etc.
//later
class Worker {
CDerived1 cd1 ;
unsigned int CDerived1Counter ;
bool CDerived1Flag ;
unsigned int CDerived1ID ;
CDerived2 cd2 ;
unsigned int CDerived2Counter ;
bool CDerived2Flag ;
unsigned CDerived2ID ;
/// etc
public :
};
The worker class has a ID, a Flag and a counter for each derived
type. An approach that in my view is just silly. So I decided to
create a repository.
struct Repository {
CBase *ptr;
unsigned int Counter ;
bool Flag ;
unsigned int ID ;
Repository ( CBase *ptr_, int BaseClassID )
: ptr ( ptr_ )
, Counter ( 0 )
, Flag ( false )
, ID ( BaseClassID )
{}
};
typedef std::vector < Repository* > REPOSITORY_VEC ;
class RevisedWorker {
static REPOSITORY_VEC rep_vec ;
public :
RevisedWorker ()
{
rep_vec.push_back ( new Repository ( new CDerived2, 0x400 ) ) ;
rep_vec.push_back ( new Repository ( new CDerived1, 0x300 ) ) ;
// would be nice if i could do.. or perhaps use a map
//rep_vec.add ( new Repository ( new CDerived2, 0x4000 ) )
// .add ( new Repository ( new CDerived1, 0x300 ) ) );
}
};
REPOSITORY_VEC RevisedWorker::rep_vec;
int main() {
RevisedWorker rw;
std::cin.get();
}
At issue: 'new' Repository 'new' CDerivedXX looks unsightey but I'm
not of a reasonable workaround. Ideas? Thanks in advance.