The following compiles and runs fine with MSVC:
Index: ScopedPtr.h
===================================================================
--- ScopedPtr.h (revision 10416)
+++ ScopedPtr.h (working copy)
@@ -26,6 +26,7 @@
#ifndef SCOPEDPTR_H
#define SCOPEDPTR_H
+#include "OtherFunctions.h" // Needed for DeleteContents()
/**
* CScopedPtr is a simple smart pointer.
@@ -68,7 +69,7 @@
return ptr;
}
-private:
+protected:
//@{
//! A scoped pointer is neither copyable, nor assignable.
CScopedPtr(const CScopedPtr<TYPE>&);
@@ -132,5 +133,25 @@
TYPE* m_ptr;
};
+
+template <typename STL_CONTAINER>
+class CScopedContainer : public CScopedPtr<STL_CONTAINER>
+{
+
+public:
+ /** Constructor. Note that CScopedContainer takes ownership of the array. */
+ CScopedContainer(STL_CONTAINER* ptr = 0)
+ : CScopedPtr(ptr)
+ {}
+
+ ~CScopedContainer()
+ {
+ if (m_ptr) {
+ DeleteContents(*m_ptr);
+ }
+ // m_ptr itself is deleted in base class
+ }
+};
+
#endif // SCOPEDPTR_H
// File_checked_for_headers
but GCC barfs at it:
In file included from ../../../../trunk/src/utils/fileview/../../SafeFile.cpp:29:0:
../../../../trunk/src/utils/fileview/../../ScopedPtr.h: In constructor ‘CScopedContainer<STL_CONTAINER>::CScopedContainer(STL_CONTAINER*)’:
../../../../trunk/src/utils/fileview/../../ScopedPtr.h:144:5: error: class ‘CScopedContainer<STL_CONTAINER>’ does not have any field named ‘CScopedPtr’
../../../../trunk/src/utils/fileview/../../ScopedPtr.h: In destructor ‘CScopedContainer<STL_CONTAINER>::~CScopedContainer()’:
../../../../trunk/src/utils/fileview/../../ScopedPtr.h:149:7: error: ‘m_ptr’ was not declared in this scope
make[4]: *** [mulefileview-SafeFile.o] Error 1
Is it just me or is this more complicated?