2

I have 3 files

dimentions.h:

namespace mtm { 
    class Dimensions {
        int row, col;
        //some code
    };
}

IntMatrix.h:

#include "dimentions.h"
namespace mtm 
{ 
    class intMatrix
    {
    private:
        int** data;
        int col;
        int row;

    public:
        intMatrix(Dimensions dims, int num=0);
        //some code
    };

    //the line bellow is where I get the error
    intMatrix(Dimensions dims, int num=0): col(dims.getCol()),row(dims.getRow()) ,data(new int*[dims.getRow()])
    {
        for(int i=0;i<dims.getCol())
        {
            data[i](new int[dims.getCol]);
        }
        for(int i=0;i<dims.getRow();i++)
        {
            for(int j=0;j<dims.getCol();j++)
            {
                data[i][j]=num;
            }
        }
    }
}

the compiler says: expected ‘)’ before ‘dims’ and when I put the mouse at dims, vs code says: " error-type mtm::dims" but dims is not a type it is a vriable.

IntMatrix.cpp:

#include "IntMatrix.h"
using namespace mtm;
//some code

in IntMatrix.cpp the problem is that it doesn't recognize what Dimentions is , however it does recognize what intMatrix is.

0

2 Answers 2

4

Welcome to StackOverflow!

Compiler messages are sometimes misleading, and in your case you have an error because you are repeating the default value in your implementation. This is probably the error the compiler is complaining about.

EDIT As pointer out by drescherjm, you also forgot the add the class name to the constructor

The correct definition should be :

intMatrix::intMatrix(Dimensions dims, int num): ...

Please let me know if you still have the error after that.

Sign up to request clarification or add additional context in comments.

1 Comment

Also the OP forgot the intMatrix:: part. And the code likely should be moved into the .cpp if the OP wants to define the constructor outside the class.
1

In your C++ source code the constructor must be defined as

intMatrix::intMatrix(Dimensions dims, int num) ....

So you have two mistakes: you have to add intMatrix and delete =0

But do not ever write a matrix class like this. This is terrible C++ code. You should never need to call new directly. And your data, in this case, is laid down very cache unfriendly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.