472,133 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

error C4430: missing type specifier - int assumed. Note: C++ does not support default

34
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
err how do i fix that error?

for example given to this section of code..
Expand|Select|Wrap|Line Numbers
  1. Matrix::addMatrix(Matrix m1, Matrix m3)
  2. {
  3.     for(int a = 0; a < row; a++)
  4.     {
  5.         for(int b = 0; b < col; b++)
  6.         {
  7.             m3[a][b]=(m1[a][b] + m2[a][b]);
  8.         }
  9.     }
  10. }
  11.  
this is the header file..
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include "Matrix.h"
  6. using namespace std;
  7.  
  8. class Matrix
  9. {
  10. public:
  11.     Matrix(void);
  12.     ~Matrix(void);
  13.     void readMatrixFile(string FILENAME);
  14.     void addMatrix(Matrix m1, Matrix m3);
  15.     void displayMatrix();
  16.     void transposeMatrix();
  17.     void multiplyMatrices(Matrix m2, Matrix m3);
  18.  
  19. private:
  20.     int row;
  21.     int col;
  22.     /*m = new (double*)[10];
  23.     for(int i = 0; i < 10; i++)
  24.     {
  25.         m[i] = new double[10];
  26.     }
  27.     for(int j = 0; j < 10; j++...)
  28.     {
  29.         delete[] m[i];
  30.     }
  31.     delete[] m;*/
  32.     double m[][];
  33. };
  34.  

please help me.
thanks in advance :)
Jul 31 '08 #1
12 38540
arnaudk
424 256MB
The variables 'row' and 'col' appear to be undeclared when you are using them. Maybe you mean this->row and this->col?
Jul 31 '08 #2
slizorn
34
The variables 'row' and 'col' appear to be undeclared when you are using them. Maybe you mean this->row and this->col?

the thing is i am using the row and col as a variable to be used by several matrices under the Matrix class..


i have posted the code below for yr kind reference
thanks
Jul 31 '08 #3
slizorn
34
Matrix.cpp file

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include "Matrix.h"
  5. using namespace std;
  6.  
  7.  
  8. Matrix::Matrix(void)
  9. {
  10. }
  11.  
  12.  
  13. Matrix::~Matrix(void)
  14. {
  15. }
  16.  
  17.  
  18. Matrix::readMatrixFile(string FILENAME)
  19. {
  20.     const string filename(FILENAME);
  21.     ifstream file(filename.c_str());
  22.     string line;
  23.     if (getline(file, line) && line == "<matrix>")
  24.     {
  25.         if (file >> line /* "rows" */ && file >> line /* "=" */ && file >> row && getline(file,line) /* ; */)
  26.         {
  27.             if (file >> line /* "cols" */ && file >> line /* "=" */ && file >> col && getline(file,line) /* ; */)
  28.             {
  29.                 for (int r = 0; r < row; r++)
  30.                 {
  31.                     for (int c = 0; c < col; c++)
  32.                     {
  33.                         int value;
  34.                         if (file >> value)
  35.                         {
  36.                             m[r][c] = value;
  37.                         }
  38.                     }
  39.                     cout << endl;
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
  45.  
  46.  
  47. Matrix::addMatrix(Matrix m1, Matrix m3)
  48. {
  49.     for(int a = 0; a < row; a++)
  50.     {
  51.         for(int b = 0; b < col; b++)
  52.         {
  53.             m3[a][b]=(m1[a][b] + m2[a][b]);
  54.         }
  55.     }
  56. }
  57.  
  58.  
  59. Matrix::displayMatrix()
  60. {
  61.     for(int i = 0; i < row; i++)
  62.     {
  63.         cout << "| ";
  64.         for (int j = 0; j < col; j++)
  65.         {
  66.             cout << m3[i][j] << " ";
  67.         }
  68.         cout << "|" << endl;
  69.     }
  70. }
  71.  
  72.  
  73. Matrix::transposeMatrix()
  74. {
  75.     Matrix m1, m3;
  76.     for(int k = 0; k < row; k++)
  77.     {
  78.         for(int j = 0; j < col; j++)
  79.         {
  80.             int save[2][2];
  81.             save[k][j] = m1[k][j];
  82.             m3[k][j] = m1[j][k];
  83.             m3[j][k] = save[k][j];
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89. Matrix::multiplyMatrices(Matrix m2, Matrix m3)
  90. {
  91.     if(m1.col != m2.row)
  92.     {
  93.         cout << "These two matrices cannot be multiplied!!!" << endl;
  94.     }
  95.     else
  96.     {
  97.         for(int i = 0; i < m1.row; i++)
  98.         {
  99.             for(int j = 0; j < m2.col; j++)
  100.             {
  101.                 m3[i][j] = 0;
  102.                 for(int k = 0; k < m2.row; k++)
  103.                 {
  104.                     m3[i][j] = m3[i][j] + m1[i][k] * m2[k][j];
  105.                 }
  106.             }
  107.         }
  108.     }
  109. }
  110.  

another cpp file juz to store my int main() in..
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include "Matrix.h"
  5. using namespace std;
  6.  
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10.     Matrix m1, m2 ,m3;
  11.     char theOption, whichMatrixToDisplay;
  12.     string filename1, filename2;
  13.  
  14.     while(theOption != '5')
  15.     {
  16.         cout << "Please choose one of the following options from the menu below:" << endl;
  17.         cout << "---------------------------------------------------------------" << endl;
  18.         cout << "(1) Add two matrices" << endl;
  19.         cout << "(2) Multiply two matrices" << endl;
  20.         cout << "(3) Take transpose of a matrix" << endl;
  21.         cout << "(4) Display a matrix" << endl;
  22.         cout << "(5) Exit" << endl;
  23.         cout << "---------------------------------------------------------------" << endl;
  24.         cin >> theOption;
  25.  
  26.         switch(theOption)
  27.         {
  28.             case '1':
  29.                 cout << "You have chosen option 1!: Add two matices!" << endl;
  30.                 cout << "Please enter the two filenames that contain the two input matrices respectively!" << endl;
  31.                 cout << "Enter name of 1st file" << endl;
  32.                 cin >> filename1;
  33.                 cout << "Enter name of 2nd file" << endl;
  34.                 cin >> filename2;
  35.                 m1.readMatrixFile(filename1);
  36.                 m2.readMatrixFile(filename2);
  37.                 m2.addMatrix(m1, m3);
  38.                 cout << "The two matrices have been added together." << endl;
  39.                 cout << "Select (4): Display a matrix to view it." << endl << endl;
  40.                 break;
  41.  
  42.             case '2':
  43.                 cout << "You have chosen option 2!: Multiply two matices!" << endl;
  44.                 cout << "Please enter the two filenames that contain the two input matrices respectively!" << endl;
  45.                 cout << "Enter name of 1st file" << endl;
  46.                 cin >> filename1;
  47.                 cout << "Enter name of 2nd file" << endl;
  48.                 cin >> filename2;
  49.                 m1.readMatrixFile(filename1);
  50.                 m2.readMatrixFile(filename2);
  51.                 m1.multiplyMatrices(m2, m3);
  52.                 cout << "The two matrices have been multiplied with each other." << endl;
  53.                 cout << "Select (4): Display a matrix to view it." << endl << endl;
  54.                 break;
  55.  
  56.             case '3':
  57.                 cout << "You have chosen option 3!: Transpose a matrix!" << endl;
  58.                 cout << "Please enter the filename that contains the matrix to be transposed!" << endl;
  59.                 cout << "Enter name of file" << endl;
  60.                 cin >> filename1;
  61.                 m1.readMatrixFile(filename1);
  62.                 m1.transposeMatrix();
  63.                 cout << "The matrix has been transposed." << endl;
  64.                 cout << "Select (4): Display a matrix to view it." << endl << endl;
  65.                 break;
  66.  
  67.             case '4':
  68.                 cout << "You have chosen option 4!: Display a matix!" << endl;
  69.                 cout << "Please enter the option 1, 2 or 3 to display the respective matrices!" << endl;
  70.                 cin >> whichMatrixToDisplay;
  71.                 if(whichMatrixToDisplay == '1')
  72.                     m1.displayMatrix();
  73.                 else if(whichMatrixToDisplay == '2')
  74.                     m2.displayMatrix();
  75.                 else if(whichMatrixToDisplay == '3')
  76.                     m3.displayMatrix();
  77.                 cout << endl;
  78.                 break;
  79.  
  80.             case '5':
  81.                 cout << "You have chosen the option to Quit. Goodbye!" << endl;
  82.                 break;
  83.  
  84.             default:
  85.                 cout << " Sorry the option chosen is invalid. Please enter a valid option!" << endl << endl;
  86.                 break;
  87.         }
  88.     }
  89.  
  90.     return 0;
  91. }
  92.  

the code is as above..
please let me know if u need me to send u the file..
any help is appreciated..
thanks in advance..
Jul 31 '08 #4
arnaudk
424 256MB
There's no need to double post your code.
I'm sorry, it appears that row or col are indeed declared, but m2 isn't. And unless you've overloaded operator[], which it appears you haven't, then

m3[a][b]=(m1[a][b] + m2[a][b]);

doesn't do what you think it does. I think you mean

m3.m[a][b]=(m1.m[a][b] + m[a][b]);

You might also want to check that the matrices being added are of the same rank, it makes no sense to add matrices of different ranks.
Jul 31 '08 #5
Savage
1,764 Expert 1GB
Watch out for your m1,m2 and m3 variables.
Make sure they are inside function scope before using them.

The problem is not only in that function but in MultiplyMatrices also.
Jul 31 '08 #6
slizorn
34
There's no need to double post your code.
I'm sorry, it appears that row or col are indeed declared, but m2 isn't.
well m2 will onli be defined based on the fact that m2 is the matrix that is passed through the readMatrixFromFile..
is there any other way i shd define the matrix???

and could ya also help me out with the constructor and destructor in the Matrix.cpp file? i am lost in that topic and it would be great to have this program up and runnign by saturday.. as i have already spent 1+ week doing this..

and is there a need for me to make this Matrix::displayMatrix() void???
well as u can see according to this post topic i get that error abt 10 times in my program and would really love to get rid of it...

plus i am at 31 errors currently..
can u see any other mistakes that i have done?

and please please help me do that constructor and destructor section.. or atleast give me a sample so i know wat to do....
Jul 31 '08 #7
slizorn
34
There's no need to double post your code.
I'm sorry, it appears that row or col are indeed declared, but m2 isn't. And unless you've overloaded operator[], which it appears you haven't, then

m3[a][b]=(m1[a][b] + m2[a][b]);

doesn't do what you think it does. I think you mean

m3.m[a][b]=(m1.m[a][b] + m[a][b]);

yeap u r right... the problem was that i took this exercise too lightly and according to another guy i ended up doin it as a C programm.. so i wanted to change it back to C++ cos thats wat i need to learn..

so i have made similar mistakes with the other eqns as well?

well accordin to the other post its the multiplyMatrix();
could someone check the following for me plz?

i changed it to m3.m[i][j] = m3.m[i][j] + m[i][k] * m2.m[k][j];
from m3[i][j] = m3[i][j] + m1[i][k] * m2[k][j];

and to m3.m[i][j] = 0; from m3[i][j] = 0;

correct????
Jul 31 '08 #8
slizorn
34
Watch out for your m1,m2 and m3 variables.
Make sure they are inside function scope before using them.

The problem is not only in that function but in MultiplyMatrices also.

fixed that problem :) thanks

can/do u see any other silly mistakes that i have made???
and how to do the constructors and destructors bit under the Matrix.cpp file????
thanks in advance :)
Jul 31 '08 #9
arnaudk
424 256MB
Writing an constructor/destructor is very easy, once you know what they do. But you will never manage to write your matrix class properly until you understand what they are for.
In a nutshell, the constructor creates the object in the memory, optionally setting it up with any supplied arguments, it initializes the object's internal variables. The destructor doesn't usually do much (it does causes things to happen behind the scenes), but you do need to make sure that any 'new' in the constructor is matched by a corresponding 'delete' in the destructor to avoid memory leaks.
You really need to read up a bit on rudimentary C++, I'd take some time to do that first before carrying on.
Jul 31 '08 #10
slizorn
34
Writing an constructor/destructor is very easy, once you know what they do. But you will never manage to write your matrix class until you understand what they are for.
In a nutshell, the constructor sets up the object with the supplied arguments, it initializes the object's internal variables. The destructor doesn't usually do much (it does causes things to happen behind the scenes), but you do need to make sure that any 'new' in the constructor is matched by a corresponding 'delete' in the destructor to avoid memory leaks.
You really need to read up a bit on the rudimentary C++, I'd take some time to do that first before carrying on.

i will follow yr advice...
i will read up on the rudimentary C++...
also do u reckon i will need to use the new and delete in this program?
i think the onli reason i shd be using it is if the size is unknown...
but if we can define the maximum size of the matrix to be 10 by 10 then we shd be able to do it right? but how?
Jul 31 '08 #11
Studlyami
464 Expert 256MB
Your function definitions in Matrix.cpp needs to include the return type. The error is telling you that C++ does not support a default return type so you have to specify one.
Expand|Select|Wrap|Line Numbers
  1. Matrix::addMatrix(Matrix m1, Matrix m3)
  2.  
  3. needs to be changed to
  4.  
  5. void Matrix::addMatrix(Matrix m1, Matrix m3)
  6.  
You will need to do that to all your other function calls, but not on the constructor or destructor.
Jul 31 '08 #12
slizorn
34
Your function definitions in Matrix.cpp needs to include the return type. The error is telling you that C++ does not support a default return type so you have to specify one.
Expand|Select|Wrap|Line Numbers
  1. Matrix::addMatrix(Matrix m1, Matrix m3)
  2.  
  3. needs to be changed to
  4.  
  5. void Matrix::addMatrix(Matrix m1, Matrix m3)
  6.  
You will need to do that to all your other function calls, but not on the constructor or destructor.

thanks :D
i have reduced the errors to just 9 now...
they are as follows:
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.h(32) : error C2087: 'm' : missing subscript
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.h(32) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1> Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(67) : error C2676: binary '[' : 'Matrix' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(82) : error C2676: binary '[' : 'Matrix' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(83) : error C2676: binary '[' : 'Matrix' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(83) : error C2676: binary '[' : 'Matrix' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(84) : error C2676: binary '[' : 'Matrix' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(92) : error C2228: left of '.col' must have class/struct/union
1> type is 'double [][1]'
1>c:\users\slizorn\documents\visual studio 2008\projects\exercise2\matrix.cpp(98) : error C2228: left of '.row' must have class/struct/union
1> type is 'double [][1]'
Jul 31 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by darko | last post: by
2 posts views Thread by LifeStory via DotNetMonster.com | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.