 |
|
 |
I added Matrix.h and matrix.cpp to my MFC project in vc++ but it gave me over 25 errors when compliling:
Error 1 error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *' e:\thesis\projects\testimageapp\matrix.cpp 996 Error 2 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1035 Error 3 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1038 Error 4 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1041 Warning 5 warning C4996: 'CFileException::generic' was declared deprecated e:\thesis\projects\testimageapp\matrix.cpp 1043 Error 6 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1044 Error 7 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1047 Error 8 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1050 Error 9 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1053 Error 10 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1056 Error 11 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1059 Error 12 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1062 Error 13 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1065 Error 14 error C2664: 'atof' : cannot convert parameter 1 from 'CString' to 'const char *' e:\thesis\projects\testimageapp\matrix.cpp 1101 Error 15 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1133 Error 16 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1136 Error 17 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1139 Warning 18 warning C4996: 'CFileException::generic' was declared deprecated e:\thesis\projects\testimageapp\matrix.cpp 1141 Error 19 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1142 Error 20 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1145 Error 21 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1148 Error 22 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1151 Error 23 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1154 Error 24 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1157 Error 25 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1160 Error 26 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types e:\thesis\projects\testimageapp\matrix.cpp 1163 Error 27 error C2664: 'void ATL::CStringT<basetype,stringtraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *' e:\thesis\projects\testimageapp\matrix.cpp 1184
what is wrong with it? what should I do to fix it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, I can not download the sources files from the link. Can you give me a copy. My e-mail address is: whb111@uestc.edu.cn.
Thanks, Best regards.
Wang Hongbing
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
i want to add the CNatrix class into my dll proj but its showing error. why the CObject is kept as base. can i use this class in proj other than MFC's
My small attempt...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi! Here is a better version of the serialization function for class CMatrix. The version from the original class is indeed more clear, but if you intend to use it in an application and use high order matrices this can lead to unneccessary operations, such as loops and assignments.
void CMatrix::Serialize(CArchive& ar) { CObject::Serialize(ar);
if(ar.IsStoring()) { ar << header1; ar << header2; ar << version;
ar << m_NumColumns; ar << m_NumRows; ar.Write(m_pData, sizeof(double) * m_NumColumns * m_NumRows); } else { long h1, h2; int ver;
ar >> h1; ar >> h2; if(h1 != header1 || h2 != header2) { AfxThrowArchiveException(CArchiveException::badClass, NULL); } ar >> ver; ASSERT(ver == version);
ar >> m_NumColumns; ar >> m_NumRows; ar.Read(m_pData, sizeof(double) * m_NumColumns * m_NumRows); } } Variables header1, header2 and version are defined in "Matrix.h":
#define header1 0x434d6174 #define header2 0x72697843 #define version 1 I think it's a good idea to separate the signature and version of the object beeing serialized from the serialization code so that when you modify it, you won't have to go through all the serialization code to update the values, you simply modify them where they are declared. That's it. It doesn't do much but I am working a lot with serialization and I thought that I can give a helping hand on updating this class.
I am in love with VC++
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi! Here is how you can use this class In Visual C++ 6.0.
1) Open Visual C++ 6.0 application. 2) Select File -> New -> Win32 Console Application. Select the desired location for your project and give it a name, let's say MatrixPrj. Click OK. 3) In the dialog box that appears select option "An application that supports MFC" and click Finish. 4) In the last step click OK to finish. 5) Copy the files "Matrix.h" and "Matrix.cpp" in your project's folder. 6) Select Project -> Add To Project -> Files. Select the files "Matrix.h" and "Matrix.cpp" and click OK. Now the two files are added to your project. 7) Go to file "Matrix.h" where CMatrixHelper class is defined, go to function void operator=(CMatrixHelper& other) and replace the following line of code:
m_pMatrixConst = other.m_Col; with this one:
m_pMatrixConst = other.m_pMatrixConst; 8) Now compile the entire project and you are ready to use the functionality of this class.
I am in love with VC++
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I was interested in the suggestion of eliminating the helper class below, but as a beginner I am not sure how to implement the suggestion. Does anyone have updated matrix.h and matrix.cpp incorporating the suggestion? Hopefully it would also eliminate the error LNK2001: unresolved external symbol __endthreadex and __beginthreadex. Thank you.
cwb
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
I fixed the compile error and then received the following link errors. From reading through the F1 help on LNK2001, it sounds like playing with the project compile or link settings could potentially fix the errors (or possibly produce more subtle errors). Any advice on these and possibly other problems down the road?
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
cwb
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi....
I tried to create a CMatrix object using CMatrix(); but the compiler could not compile saying there is errors as follows ;
Linking... Global.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CMatrix::~CMatrix(void)" (??1CMatrix@@UAE@XZ) Global.obj : error LNK2001: unresolved external symbol "public: __thiscall CMatrix::CMatrix(void)" (??0CMatrix@@QAE@XZ) Debug/painter.exe : fatal error LNK1120: 2 unresolved externals
Anybody that can help me resolve the following errors ?? Thanks alot cos i just started learning how to program in visual c....
|
| Sign In·View Thread·PermaLink | 1.67/5 (2 votes) |
|
|
|
 |
|
 |
Hi!
I'm interested in using the matrix class, however and since I'm a newbie I don't know how to use it... can you send me a small example for Microsoft Visual C++ 6.0, creating and adding 2 matrixes? jolival@av.it.pt
Thanks, Best regards,
João Olival
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Funny Business A man is opening a restaurant and he asks one of his workers to come up with a name for it. The man tells Al, one of his workers, that he will name the resaurant after the first thing Al sees when he goes out the door.
Al walks outside and the first thing he saw was a girl named Lucy and he saw her legs. He told the man, and so the restaurant was named Lucy's Legs. The man was so impressed that he said the next day Al could get a free drink.
The next day Al comes a bit early and a policeman walks by and notices Al waiting there. The policeman asks, "What are you doing?"
Al says, "I'm waiting for Lucy's legs to open so I can get a drink."
;P
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
How are you? Your Class Matrix is very interesting i like a lot.
But i dont undenstand the way to introduce the values in matrix
You put *mpData and you put that use the CMatrixHelper to simulate [][] but dont put any example
Please Help me
Thanks very much
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
as I use the function CMatrix::Invert(),I found sometimes it doesn't work well at all,cannot calculate exactly real Invert Matrix,sometimes it is right,sometimes it is wrong,is there any problem in your programming?please check it and give me the answer
|
| Sign In·View Thread·PermaLink | 1.67/5 (3 votes) |
|
|
|
 |
|
 |
to rogen allen... im very weak in c++ programming..ihope u can help me to solve my prob.. how to use cmatrix and can u give me some tutorial..then can u give me some example source code to prove eigen value and vector prob in c++
need for help
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi all...i m a beginner in programming..so i tried to get benifit of the code of matrix class written by Roger Allen but there was an error coz he didnt attach "stdafx.h" with his code...so if any one can help me with that...tnx
Madoo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Can anybody help me?? When comiling the code in VC7, I've got this:
Matrix.cpp(1022): error C2316: 'CFileException &' : cannot be caught as the destructor and/or copy constructor are inaccessible
Thx...
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
This is the code i am having in visual c++ 6. Matrix.h & matrix.cpp are in current project folder and included in project.
#include #include "matrix.cpp" void main() { CMatrix:: A(); }
But i am getting an error that
matrix.h(191) :error C2440: '=' : cannot convert from 'int' to 'const class CMatrix *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Please tell me what to be done. Thanks
Nagarajan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Now that probelem is correted by explicit type casting.. The program compiles without any error.
#include #include "matrix.cpp" using namespace std;
void main() {
CMatrix A(3,4); }
But while linking i get 151 errors.
like
Matrix.obj : error LNK2005: "public: static class CObject * __stdcall CMatrix::CreateObject(void)" (?CreateObject@CMatrix@@SGPAVCObject@@XZ) already defined in mat.obj Matrix.obj : error LNK2005: "public: virtual struct CRuntimeClass * __thiscall CMatrix::GetRuntimeClass(void)const " (?GetRuntimeClass@CMatrix@@UBEPAUCRuntimeClass@@XZ) already defined in mat.obj Matrix.obj : error LNK2005: "class CArchive & __stdcall operator>>(class CArchive &,class CMatrix * &)" (??5@YGAAVCArchive@@AAV0@AAPAVCMatrix@@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: __thiscall CMatrix::CMatrix(void)" (??0CMatrix@@QAE@XZ) already defined in mat.obj Matrix.obj : error LNK2005: "public: __thiscall CMatrix::CMatrix(class CMatrix const &)" (??0CMatrix@@QAE@ABV0@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: __thiscall CMatrix::CMatrix(int,int)" (??0CMatrix@@QAE@HH@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: __thiscall CMatrix::CMatrix(int,bool)" (??0CMatrix@@QAE@H_N@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: __thiscall CMatrix::CMatrix(struct tagVARIANT &)" (??0CMatrix@@QAE@AAUtagVARIANT@@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: virtual __thiscall CMatrix::~CMatrix(void)" (??1CMatrix@@UAE@XZ) already defined in mat.obj Matrix.obj : error LNK2005: "public: virtual void __thiscall CMatrix::Dump(class CDumpContext &)const " (?Dump@CMatrix@@UBEXAAVCDumpContext@@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: virtual void __thiscall CMatrix::AssertValid(void)const " (?AssertValid@CMatrix@@UBEXXZ) already defined in mat.obj Matrix.obj : error LNK2005: "public: virtual void __thiscall CMatrix::Serialize(class CArchive &)" (?Serialize@CMatrix@@UAEXAAVCArchive@@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "private: double * __thiscall CMatrix::AllocateMemory(int,int)" (?AllocateMemory@CMatrix@@AAEPANHH@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: class CMatrix & __thiscall CMatrix::operator=(class CMatrix const &)" (??4CMatrix@@QAEAAV0@ABV0@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: bool __thiscall CMatrix::operator==(class CMatrix const &)const " (??8CMatrix@@QBE_NABV0@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: class CMatrix __thiscall CMatrix::operator+(class CMatrix const &)const " (??HCMatrix@@QBE?AV0@ABV0@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: class CMatrix __thiscall CMatrix::operator-(class CMatrix const &)const " (??GCMatrix@@QBE?AV0@ABV0@@Z) already defined in mat.obj Matrix.obj : error LNK2005: "public: class CMatrix __thiscall CMatrix::operator*(class CMatrix const &)const " (??DCMatrix@@QBE?AV0@ABV0@@Z) already defined in mat.obj
Please help me... thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
CMatrix CMatrix::operator*(const CMatrix &other) const { // first check for a valid multiplication operation if (m_NumColumns != other.m_NumRows) throw "Matrices do not have common size" ; // now that we know that the operation is possible ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ; // construct the object we are going to return CMatrix result(other.m_NumColumns, m_NumRows);
// e.g. // [A][B][C] [G][H] [A*G + B*I + C*K][A*H + B*J + C*L] // [D][E][F] * [I][J] = [D*G + E*I + F*K][D*H + E*J + F*L] // [K][L] // double value ; for (int i = 0 ; i < result.m_NumColumns ; i++) { for (int j = 0 ; j < result.m_NumRows ; j++) { value = 0.0 ; for (int k = 0 ; k < m_NumColumns ; k++) { value += GetElement(k,j) * other.GetElement(k,i) ; } result.SetElement(i, j, value) ; } } return result ; }
Jon Gould
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Or even this.
CMatrix CMatrix::operator*(const CMatrix &other) const { // first check for a valid multiplication operation if (m_NumColumns != other.m_NumRows) throw "Matrices do not have common size" ; // now that we know that the operation is possible ASSERT(FALSE == IsBadReadPtr(other.m_pData, sizeof(double) * other.m_NumColumns * other.m_NumRows)) ; // construct the object we are going to return CMatrix result(other.m_NumColumns, m_NumRows);
// e.g. // [A][B][C] [G][H] [A*G + B*I + C*K][A*H + B*J + C*L] // [D][E][F] * [I][J] = [D*G + E*I + F*K][D*H + E*J + F*L] // [K][L] // double value ; for (int i = 0 ; i < result.m_NumColumns ; i++) { for (int j = 0 ; j < result.m_NumRows ; j++) { value = 0.0 ; for (int k = 0 ; k < m_NumColumns ; k++) { value += GetElement(k,j) * other.GetElement(i,k) ; } result.SetElement(i, j, value) ; } } return result ; }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In allthrough his code, the "m_NumColumns" should be "m_NumRows" and vice versa, I believe. But it works if you leave these names be.
Bill^2
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I think I might be missing a file or two (?), because when I compile the source, it's missing "stdafx.h" and when I comment it out I get like 50 errors (even after commenting out the MFC stuff as suggested by the author for VC++6 use) so I'm pretty sure I need that file at least. Any ideas on where I can find the misssing file(s)?
-milan
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
 |
One thing this class is missing is an algorithm to reduce a matrix to complete row-echelon form. Here is the algorithm from a matrix class that I wrote. With a few very slight changes, it can be rolled into Mr. Allen's Matrix class. This algorithm can be used to to solve systems of linear equations stored in a matrix. It also calculates the Determinant. You can also use this algorithm to find the inverse of a matrix.
The Set & Get functions will have to be revised per Mr. Allen's corresponding functions. This algorithm uses get(row, col) and set(row, col, val). Mr. Allen's equivalent functions have col first and row second.
If you find this algorithm useful, thank Gauss!
// Reduce to complete row echelon form // By James D. Reilly, Fort Wayne, Indiana double Matrix::Reduce(void) { int B, C, X; double Pivot, Temp; double Determinant; int PivotRow, PivotCol;
PivotRow = 0; PivotCol = 0; Determinant = 1.0; do { // Find largest pivot. Search for a number below // the current pivot with a greater absolute value. X = PivotRow; for(C=PivotRow; C<rows; C++) if(fabs(Get(C, PivotCol))>fabs(Get(X, PivotCol))) X = C;
if(X != PivotRow) { // If here, there is a better pivot choice somewhere // below the current pivot. // Interchange the pivot row with the row // containing the largest pivot, X. for(B=0; B<cols; B++) { Temp = Get(PivotRow, B); Set(PivotRow, B, Get(X, B)); Set(X, B, Temp); }
Determinant = -Determinant; }
Pivot = Get(PivotRow, PivotCol); Determinant = Pivot*Determinant;
if(Pivot!= 0.0) { // Introduce a '1' at the pivot point for(B=0; B<cols; B++) Set(PivotRow, B, Get(PivotRow, B)/Pivot);
for(B=0; B<rows; B++) { // Eliminate (make zero) all elements above // and below the pivot. // Skip over the pivot row when we come to it. if(B != PivotRow) { Pivot = Get(B, PivotCol); for(C=PivotRow; C<cols; C++) Set(B, C, Get(B,C)-Pivot*Get(PivotRow, C)); } } PivotRow++; // Next row } PivotCol++; // Next column } while((PivotRow<rows)&&(PivotCol<cols)); // Reached an edge yet?
return Determinant; }
J. Reilly
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |