Hello,
My setup: Debian sarge on dual Pentium 4. g++ 3.3.5-3.
(the other system is Windows XP with MS Visual Studio .NET 2003)
I have an auto_array<T> template (based on a template taken from the
Corona
project hosted at SourceForge) which basically wants to implement
std::auto_ptr<T>
semantics for an array.
It used to compile and run the test program I wrote for it but suddenly
it stopped
compiling and I have no idea what did I do wrong (or change at all).
On MS Visual Studio .NET 2003 the sample test program below (which I
clipped
down to demo the problem) compiles and runs find.
Here is the sample program:
#include <cstddef>
#include <cstring>
template<typename T>
class auto_array
{
public:
explicit auto_array (T* initial = 0) : array(initial) { }
auto_array(auto_array<T>& other) : array(other.release()) { }
~auto_array() { delete[] array; }
T* get() const { return array; }
T* release() { T* old = array; array = 0; return old; }
void reset(T* a = 0)
{
if (a != array) { delete[] array; array = a; }
}
void reset(auto_array<T>& a)
{
if (this != &a) { delete[] array; array = a.release(); }
}
auto_array<T> &operator= (T* a) { reset(a); return *this; }
auto_array<T> &operator= (auto_array<T>& a)
{
reset(a.release()); return *this;
}
private:
T* array;
};
auto_array<char> f(auto_array<char>& input) { return input; }
int main(int argc, char* argv[])
{
auto_array<char> a,b,c;
c.reset(a);
b = c;
// next two lines causes the errors
c.reset(f(b));
b = f(b);
}
The lines which cause the errors are the last two in main().
Could someone please tell where is my mistake? I can't find it myself
from digging the net or reading the books.
Thanks,
--Amos