Darko Miletic
2008-07-10 14:47:03 UTC
Here is my code (this is not the real code but represents my problem
exactly):
#ifdef __BORLANDC__
#pragma warn -inl
#endif __BORLANDC__
struct policyA {
static void doinit() {}
static void dofree() {}
};
template < typename T >
struct policyB {
static void doinit() { T::instance().get(); }
static void dofree() {}
};
template < typename HandleT, typename PolicyT >
struct singleton {
static singleton& instance (void) {
static singleton inst;
return inst;
};
HandleT get(void) const { return handle_;}
private: //commenting this makes it compile on bds
~singleton(void) {
PolicyT::dofree();
}
private:
singleton(void) : handle_(0) {
PolicyT::doinit();
}
singleton(singleton const&);
singleton& operator=(singleton const&);
volatile HandleT handle_;
};
typedef singleton< void*, policyA > singletonA;
typedef singleton< void*, policyB< singletonA > > singletonB;
int main(void) {
singletonB::instance().get();
return 0;
}
If I compile it with MSVC or comeau everything is fine, however on BDS
2006 it says:
bcc32 -q -tWC -w -Q+ prbl.cpp
prbl.cpp:
Error E2166 prbl.cpp 49: Destructor for 'singletonA' is not accessible
*** 1 errors in Compile ***
Only by commenting private specification (making destructor public) it
compiles fine.
Now who is right here? msvc/comeau or bds?
exactly):
#ifdef __BORLANDC__
#pragma warn -inl
#endif __BORLANDC__
struct policyA {
static void doinit() {}
static void dofree() {}
};
template < typename T >
struct policyB {
static void doinit() { T::instance().get(); }
static void dofree() {}
};
template < typename HandleT, typename PolicyT >
struct singleton {
static singleton& instance (void) {
static singleton inst;
return inst;
};
HandleT get(void) const { return handle_;}
private: //commenting this makes it compile on bds
~singleton(void) {
PolicyT::dofree();
}
private:
singleton(void) : handle_(0) {
PolicyT::doinit();
}
singleton(singleton const&);
singleton& operator=(singleton const&);
volatile HandleT handle_;
};
typedef singleton< void*, policyA > singletonA;
typedef singleton< void*, policyB< singletonA > > singletonB;
int main(void) {
singletonB::instance().get();
return 0;
}
If I compile it with MSVC or comeau everything is fine, however on BDS
2006 it says:
bcc32 -q -tWC -w -Q+ prbl.cpp
prbl.cpp:
Error E2166 prbl.cpp 49: Destructor for 'singletonA' is not accessible
*** 1 errors in Compile ***
Only by commenting private specification (making destructor public) it
compiles fine.
Now who is right here? msvc/comeau or bds?