Works for me on VC++ 2003. Can you post your entire piece of code?
Code:
#include <iostream>
#include <list>
#include <memory>
static bool made_one = false;
template < class T >
class Matrix
{
public:
Matrix( ) : Rows(2), Cols(2), Temp(0)
{
if (!made_one)
{
made_one = true;
Temp.reset(new Matrix<T>());
}
}
bool SquareMatrix( ) const;
std::auto_ptr< Matrix< T > >& Minor(const Matrix< T >&);
private:
unsigned int Rows, Cols;
std::list< std::list< T > > Data;
std::auto_ptr< Matrix< T > > Temp;
};
template < class T >
bool Matrix< T >::SquareMatrix( ) const
{
return (Rows == Cols);
}
template < class T >
std::auto_ptr< Matrix< T > >& Matrix< T >::Minor(const Matrix< T >& m)
{
if (m.Temp.get())
return Temp;
else if (Temp.get())
return Temp->Temp;
return Temp;
}
int main()
{
Matrix<int> m1;
Matrix<int> m2;
if (m1.SquareMatrix() && m2.SquareMatrix())
{
std::auto_ptr< Matrix< int > >& ap = m1.Minor(m2);
if (ap.get() == 0)
std::cout << "Success!\n";
else
std::cout << "Failure!\n";
}
}
With a typedef it works too:
Code:
#include <iostream>
#include <list>
#include <memory>
static bool made_one = false;
template < class T >
class Matrix
{
public:
typedef std::auto_ptr< Matrix< T > > MATRIX_PTR;
Matrix( ) : Rows(2), Cols(2), Temp(0)
{
if (!made_one)
{
made_one = true;
Temp.reset(new Matrix<T>());
}
}
bool SquareMatrix( ) const;
MATRIX_PTR& Minor(const Matrix< T >&);
private:
unsigned int Rows, Cols;
std::list< std::list< T > > Data;
MATRIX_PTR Temp;
};
template < class T >
bool Matrix< T >::SquareMatrix( ) const
{
return (Rows == Cols);
}
template < class T >
typename Matrix< T >::MATRIX_PTR& Matrix< T >::Minor(const Matrix< T >& m)
{
if (m.Temp.get())
return Temp;
else if (Temp.get())
return Temp->Temp;
return Temp;
}
int main()
{
Matrix<int> m1;
Matrix<int> m2;
if (m1.SquareMatrix() && m2.SquareMatrix())
{
Matrix<int>::MATRIX_PTR& ap = m1.Minor(m2);
if (ap.get() == 0)
std::cout << "Success!\n";
else
std::cout << "Failure!\n";
}
}