I need to write a factory in C++03 that works like so:
1) The elements created are blocks of objects
2) The factory saves references to all such sub-objects.
3) The blocks are scale-able
Meaning:
class Block{
MemberType member1;
MemberType member2;
MemberType member3;
Block(){...}
}
class Factory{
set<MemberType*> members1;
set<MemberType*> members2;
set<MemberType*> members3;
Block& makeBlockInstance(){
Block& currentBlock = *(new Block());
members1.push_back(&(currentBlock.member1));
members2.push_back(&(currentBlock.member2));
members3.push_back(&(currentBlock.member3));
return currentBlock;
}
}
- please don't mind syntax errors or minor details, the code is to make a point.
What I need is a way to add or remove members from Block
, in such a way that would AUTOMATICALLY create or delete the set<MemberType*> members#
, and the members#.push_back(...)
.
Is this possible? It seems like something that is done via reflection, but I want some non-reflection way of doing this, statically.
I would love to see a non- preprocessor way of doing this.
Until then (if at all) - here is how to make the X macro expansion conditional C++ preprocessor conditional parameter