Hello everyone. I am experienceing some rather strange behaviour regarding the instantiation of an object. It's a templated custom array type object, something like this.
template <class T> class Array
{
public:
// Construction/destruction.
Array( void );
Array( unsigned int size );
Array( const Array<T> &array );
~Array( void );
// Public members.
unsigned int size( void ) const;
// Operator overloads.
const Array<T> &operator = ( const Array<T> &array );
private:
// Private member variables.
T *array_;
unsigned int size_;
};
I then have another class that is to perform a simple difference operation on an Array<double> type object.
The function in my difference class looks like this. I've removed the actual meat of it for clarity but the error occurs before all of that anyway.
Array<double> Difference::Differentiate( const Array<double> &array )
{
Array<double> tempArray( array.size() - 1 );
return( tempArray );
}
Now to my problem. After instantiation of the object tempArray it's member variables array_ and size_ are invalid. size_ in this case should be 9 as array.size_ = 10. If I use GDB to analyse tempArray.size_ from within the Differentiate() member function it's showing a value of 4253902!
Now, the strange thing is, I know my constructor for Array<double> is working correctly because if I step into the creation of tempArray the member variables are setup correctly, but upon return from the constructor the member variables are no longer the same.
Has anybody seen behaviour like this? I'm suspecting a stack corruption maybe. I have been running with libDUMA though so it should hopefully rule that out.
Any help is greatly appreciated!