Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22375 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78208 invoked by uid 1010); 13 Mar 2006 17:19:23 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 78193 invoked from network); 13 Mar 2006 17:19:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Mar 2006 17:19:23 -0000 X-Host-Fingerprint: 194.73.73.211 c2bthomr03.btconnect.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from ([194.73.73.211:1075] helo=c2bthomr03.btconnect.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id DA/EF-55982-A99A5144 for ; Mon, 13 Mar 2006 12:19:22 -0500 Received: from va517slx (host81-134-174-53.in-addr.btopenworld.com [81.134.174.53]) by c2bthomr03.btconnect.com (MOS 3.5.9-GR) with ESMTP id ELH33244; Mon, 13 Mar 2006 17:18:41 GMT To: internals@lists.php.net Date: Mon, 13 Mar 2006 17:19:17 +0000 User-Agent: KMail/1.8 MIME-Version: 1.0 Content-Disposition: inline Message-ID: <200603131719.17718.an.dromeda@btconnect.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Subject: RESOLVED: Template Linkage for a PhpClassFactory in C++ From: an.dromeda@btconnect.com C++ Templates: The complete guide (David Vandevoorde) addresses the issue. First workaround is simply to include what would normally be the .cpp code in the .h header. Not sure that's ideal, but it works, so that's the issue resolved, (or sidelined for now). Apparently there's also export, but first is enough for the moment. Cheers, Andrew. ---------- Forwarded Message ---------- Subject: Template Linkage for a PhpClassFactory in C++ Date: Monday 13 March 2006 16:58 From: an.dromeda@btconnect.com To: internals@lists.php.net 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 class PhpClassFactory { public: static void Register(TSRMLS_D); // Call from MINIT_FUNCTION } with implementation: template void PhpClassFactory::Register(TSRMLS_D) { ::register_myclass("myclass" TSRMLS_CC); } works ONLY if the above is in the 'module.cpp' file from which the PhpClassFactory::Register(TSRMLS_C); call originates. ... whereas: void PhpClassFactory::Register(TSRMLS_D) { ::register_myclass("myclass" TSRMLS_CC); } with specified class 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::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? -------------------------------------------------------