I could be missing the point (only skimmed your mail), but you need to include your template implementation in every source file that tries to instantiate the template, e.g. by adding the code to the header file (the alternative, that is, explicitely instantiating the template in factory.cpp, would be missing the point, as you say). Anyway, this is only due to the way templates work (no code is generated unless the template is instantiated, so there's nothing the linker can link your module.cpp to) and unrelated to PHP as such.
Regards, Michael On 3/13/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > The saga continues, with progress towards a (hoped for) marriage > between Php and C++ that 'looks like' C++ to the extension developer. > > I'm exploring a templated version of PhpClassFactory (vs possible root > PhpClassFactoryObject) which is making progress, but a linking error > not dissimilar to separated C++ file is rearing its head. > > in File 1, 'module.cpp' we have a basic extension skeleton, with > PHP_MINIT_FUNCTION() > > in File2 (pair, .h, .cpp) 'factory.h/cpp' we have a fully functional and > independent set of php-class management routines in C++, > requiring a single register_myclass() call from the module.cpp file > to enable the full php-class object behaviour implmented in factory.cpp. > > Encapsulating them piecemeal into a template format/structure is working, > but with a proviso: > > template <typename T_CppClass> > class PhpClassFactory > { > public: > static void Register(TSRMLS_D); // Call from MINIT_FUNCTION > } > > with implementation: > > template<typename T> > void PhpClassFactory<T>::Register(TSRMLS_D) > { > ::register_myclass("myclass" TSRMLS_CC); > } > > works ONLY if the above is in the 'module.cpp' file from which the > PhpClassFactory<MyCppClass>::Register(TSRMLS_C); call originates. > > ... whereas: > > void PhpClassFactory<MyCppClass>::Register(TSRMLS_D) > { > ::register_myclass("myclass" TSRMLS_CC); > } > > with specified class <MyCppClass> works from the separate 'factory.cpp' > file as intended, but with the cost that the very point of the templated class > is lost, as we have to explicitly declare the MyCppClass, rather than letting > the intended templated form PhpClassFactory<T>::Register(TSRMLS_D) > do the instantiation. > > Somehow, the linker can handle the generic form as long as it's in the > same object as the caller, or the class-specific form in a separate object, > but neither of these is ideal/intended. Obviously, we'd like to be able to > link to the generic form in the separate form, so it can be a simple include > to instantiate a php-object based on a cpp-class. > > Another extern/linker issue I'm afraid. Any thoughts? > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php