Hi All,

I am using the prototype design pattern to design a static library in linux.

the class architecture looks like below:

Code:
//Product.h
class Product
{
public:
   virtual ~Product() {}
   virtual Product* clone() const = 0;
   static Product* makeProduct(string type);
   static Product* addPrototype(string type, Product* p);
   static map<string, Product*>& getMap()
   {
        static map<string, Product*> protoTable;
        return protoTable;
   }
};

#define IMPLEMENT_CLONE(TYPE) \
   Product* clone() const { return new TYPE(*this); }

#define MAKE_PROTOTYPE(TYPE) \
   Product* TYPE ## _myProtoype = \
      Product::addPrototype(#TYPE, new TYPE());

Code:
// product1.h
#include "product.h"

class Product1: public Product
{
public:
   IMPLEMENT_CLONE(Product1)
   // etc.
};
Code:
// product1.cpp
#include "product1.h"
MAKE_PROTOTYPE(Product1)
// etc.

Code:
//in test.cpp
int main()
{
    Product* pObj = Product::makeProduct("Product1");
   // etc.
}
all subclass of Product will exist in their own .o file, like Product1.o, Product2.o ......
and they will be grouped into a libProduct.a static lib.

Code:
gcc test.o libProduct.a
problem is that my test main program it does not know the existence of Product1 and Product2 for example, then Product1.o and Product2.o will not be linked. And when I was trying to create the Prodcut1 object as in the test main function, it will return NULL pointer.

Your ideas and expertise advice is very appreciated.

Thanks a lot in advance!
sandodo