![]() |
| | #1 | |
| Registered User Join Date: May 2006
Posts: 894
| Weird errors. I'm getting many errors I have no idea how to correct them. The code seems fine to me but it does look like it isn't. Code: #ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <list>
template < class T >
class Matrix
{
public:
bool SquareMatrix( );
static MATRIX_PTR Minor(const Matrix< T >&);
private:
typedef std::auto_ptr< Matrix< T > > MATRIX_PTR;
unsigned int Rows, Cols;
std::list< std::list< T > > Data;
MATRIX_PTR Temp;
};
template < class T >
bool Matrix< T >::SquareMatrix( )
{
return (Rows == Cols);
}
template < class T >
MATRIX_PTR Matrix< T >::Minor(const Matrix< T >& m)
{
}
#endif // MATRIX_H_INCLUDED
Quote:
| |
| Desolation is offline | |
| | #2 |
| Registered User Join Date: Jan 2005
Posts: 7,137
| You should place the typedef before the code that uses it (Minor returns a MATRIX_PTR). I'm not sure if that will solve the problem, but if you haven't tried it already I'd do that. Just add a private block above the public one. Of course, can you return a private typedef from a public function? You might have to make the typedef public. |
| Daved is offline | |
| | #3 |
| Registered User Join Date: May 2006
Posts: 894
| I put that typedef up there in the public section, before the two functions and I get the same errors. I also tried adding an empty constructor, just in case, but it didn't change anything either. |
| Desolation is offline | |
| | #4 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| You should #include <memory> to use auto_ptr.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #5 |
| Registered User Join Date: May 2006
Posts: 894
| Ahah, thanks. I still get the same errors though. |
| Desolation is offline | |
| | #6 |
| Registered User Join Date: May 2006
Posts: 894
| There is an issue I see though. I have an auto_ptr to a Matrix, however it is impossible to have a class object of type Foo inside class Foo itself. I don't know how to get around of this.. |
| Desolation is offline | |
| | #7 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| A pointer to an object is not the same as an object directly. How do the errors change if you replace the auto_ptr with a raw pointer, though? (Just out of interest.)
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #8 |
| Registered User Join Date: May 2006
Posts: 894
| It doesn't change anything. I have tried right after posting. I knew that trick already but I think an auto_ptr<> is much more suited to my needs. Basically what I want to do is have a temp object for when I don't want to modify a matrix but rather return a matrix derived from it. For example return a minor, its transposed matrix, upper triangle, lower triangle.. I also removed the static keyword which I don't even know why I put it there in the first place but still no changes... I can't even see what's wrong.. =/ Especially when I check what MSDN has to say about the first error: http://msdn2.microsoft.com/en-us/library/wx7x0ezw.aspx |
| Desolation is offline | |
| | #9 |
| Registered User Join Date: May 2007
Posts: 88
| It's the typedef that's the source of your pain. This compiles with g++: Code: #ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <list>
#include <memory>
template <class T>
class Matrix
{
public:
bool SquareMatrix( );
static 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( )
{
return (Rows == Cols);
}
template <class T>
std::auto_ptr< Matrix<T> > Matrix<T>::Minor(const Matrix<T>& m)
{
}
|
| UMR_Student is offline | |
| | #10 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
Code: #ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <list>
#include <memory>
template < class T >
class Matrix
{
public:
typedef std::auto_ptr< Matrix< T > > MATRIX_PTR;
bool SquareMatrix( );
static 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( )
{
return (Rows == Cols);
}
template < class T >
typename Matrix<T>::MATRIX_PTR Matrix< T >::Minor(const Matrix< T >& m)
{
}
#endif // MATRIX_H_INCLUDED
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #11 |
| Registered User Join Date: May 2006
Posts: 894
| I already tried without typedef'ing and got the same errors. I also tried the typename trick and got the very same errors. I left the typedef public but it didn't change anything either. I tried cleaning and rebuilding the solution as well but the result is the same. |
| Desolation is offline | |
| | #12 |
| Registered User Join Date: May 2006
Posts: 894
| I have tried creating a completely new empty command line project and got the very same errors with the following code: Code: #ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <list>
#include <memory>
template < class T >
class Matrix
{
public:
Matrix( ) { }
bool SquareMatrix( );
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( )
{
return (Rows == Cols);
}
template < class T >
std::auto_ptr< Matrix< T > >& Matrix< T >::Minor(const Matrix< T >& m)
{
}
#endif // MATRIX_H_INCLUDED
Edit: I posted the question on another forum. If they have an answer, I'll let you guys know. Last edited by Desolation; 05-08-2007 at 05:13 PM. |
| Desolation is offline | |
| | #13 |
| Registered User Join Date: Jan 2005
Posts: 7,137
| 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";
}
}
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";
}
}
Last edited by Daved; 05-08-2007 at 05:41 PM. |
| Daved is offline | |
| | #14 |
| Registered User Join Date: May 2006
Posts: 894
| Your code works for me too. What did you change ? Thanks a lot, by the way. =) PS: I didn't have anything else. I just had a blank .cpp file which only included matrix.h so that it would compile the code. |
| Desolation is offline | |
| | #15 |
| Registered User Join Date: May 2006
Posts: 894
| I copied my old code into a new project and added an empty main() function and it compiled. Does anyone know why it does so ? |
| Desolation is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HELP with DX9 Errors!!! | Tommaso | Game Programming | 7 | 06-28-2006 02:51 PM |
| Errors with header files in OpenGL using VisualC++ | wile_spice | Game Programming | 3 | 06-22-2006 08:56 AM |
| Weird Errors in VS 2003 | Devil Panther | Windows Programming | 1 | 10-01-2005 06:16 AM |
| executing errors | s0ul2squeeze | C++ Programming | 3 | 03-26-2002 01:43 PM |