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: [EMAIL PROTECTED]
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 <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

Reply via email to