templated 'handle' in pimpl code? (Slightly off topic)
Hi,
I wondered if there are any examples of a templated handle class
within the boost code base I could look at?
I'm trying to hide both the implementation of the body class and that
of the template type, something like that below but my compiler is
complaining about partial specialization in the declaration of the
implementation class in handle.cpp
I know its not strictly boost related, but I don't get any of the
comp.lang.* groups.
Also before anybody suggests I should be using a smart pointer for the
impl variable I'd like to avoid having to introduce the boost library
to the user of the two .h files.
My goal was that the users would only need the *.h files and I could
provide fred.o fred2.o fred3.o etc. as new options for "fred" come
along.
I know that using the template doesn't appear to be getting me
anywhere towads my original goal (generally needing the implementation
to get the templated code to work!) but I'd like to see if I could at
least get the code to compile by studying anything similar as it may
have some use in other areas.
Thanks
Kevin
// -------------- fred.h
class fred
{
public:
void somefunction();
};
// -------------- handle.h
template <typename T>
class handle
{
public:
handle();
~handle();
void callsomefunctionviaimpl();
private:
template <typename U> class handleimpl;
handleimpl<T> *impl;
};
// -------------- fred.cpp
#include <iostream>
using namespace std;
#include "fred.h"
void fred::somefunction()
{
cout << "fred::somefunction()" << endl;
}
// -------------- handle.cpp
#include <iostream>
using namespace std;
#include "handle.h"
template
Kevin Wheatley wrote:
I'm trying to hide both the implementation of the body class and that of the template type, something like that below but my compiler is complaining about partial specialization in the declaration of the implementation class in handle.cpp
So a few hours of sleep and the BFO is apparent... my problem was 'solvable' by moving the nested template class outside of the handle class scope: //handle.h #ifndef handle_h #define handle_h template <typename U> class handleimpl; template <typename T> class handle { public: handle(); ~handle(); void callsomefunctionviaimpl(); private: handleimpl<T> *impl; }; #endif Although it still leaves me with the problem of templated handle/body requiring the code to the impl to work, I guess in my case I shall move the member T into the handle as it's essentially static const data anyway. Kevin -- | Kevin Wheatley | These are the opinions of | | Senior Do-er of Technical Things | nobody and are not shared | | Cinesite (Europe) Ltd | by my employers |
participants (1)
-
Kevin Wheatley