Hi, I'm getting this error:
Asig 2.cpp In function `void ManiMatrix()': 31
Asig 2.cpp expected primary-expression before "int"
Asig 2\Makefile.win [Build Error] ["Asig 2.o"] Error 1

Here is how I'm calling it from main: customMatrix.checkIfMagic();
Prototype in the class: void checkIfMagic(int**);
void matrix::checkIfMagic(int **arrayOfArray)
{// function began


} // function end
Any suggestion will be appreciated.

Recommended Answers

All 12 Replies

Asig 2.cpp In function `void ManiMatrix()': 31

I don't see anything wrong with checkIfMagic . But what is this function void ManiMatrix() in the first warning? Also make sure that Mani is not a misspelling for Main .

I don't see anything wrong with checkIfMagic . But what is this function void ManiMatrix() in the first warning? Also make sure that Mani is not a misspelling for Main .

Well sorry I said in the main but I´m calling the customMatrix.checkIfMagic() from a function include in the main. I also calls another function from there without any problem. I use Void ManiMatrix to call the functions that are in the class.

So what you're saying is that you have a function called ManiMatrix which is supposed to call customMatrix.checkIfMagic() ? In that case, could you post the the line in which you call checkIfMagic() in a little bit of context? The compiler error mentions 'int', which I haven't seen yet.

Please use code tags when you post code!

So what you're saying is that you have a function called ManiMatrix which is supposed to call customMatrix.checkIfMagic() ? In that case, could you post the the line in which you call checkIfMagic() in a little bit of context? The compiler error mentions 'int', which I haven't seen yet.

Please use code tags when you post code!

Yes, this is the code:

void ManiMatrix ()
{ // ManiMatrix began
matrix customMatrix;

customMatrix.createFile();
customMatrix.readFileIntoArray();
customMatrix.checkIfMagic();
} // ManiMatrix end

Updated error:

Asig 2\Asig 2.cpp In function `void ManiMatrix()': 
Asig 2\Asig 2.cpp no matching function for call to `matrix::checkIfMagic()' 
Asig 2\matrix.h:118 candidates are: void matrix::checkIfMagic(int**) 
Asig 2\Makefile.win [Build Error]  ["Asig 2.o"] Error 1

Well, that's because you coded your function to accept int ** as a parameter, and you're calling it without any arguments.

Well I want to pass an array that is inside the class, how I do that?
I try this but I got error:

{ // ManiMatrix began
matrix customMatrix;

customMatrix.createFile();
customMatrix.readFileIntoArray();
customMatrix.checkIfMagic(arrayOfArray);
} // ManiMatrix end
I:\Class\CCOM 4005\Asig\Asig 2\Asig 2.cpp In function `void ManiMatrix()': 
31 I:\Class\CCOM 4005\Asig\Asig 2\Asig 2.cpp `arrayOfArray' undeclared (first use this function) 
  (Each undeclared identifier is reported only once for each function it appears in.) 
 I:\Class\CCOM 4005\Asig\Asig 2\Makefile.win [Build Error]  ["Asig 2.o"] Error 1

>Well I want to pass an array that is inside the class, how I do that?
I'm assuming you mean that the array is a member of matrix . In that case, you'd call the function like this:

customMatrix.checkIfMagic( customMatrix.arrayOfArray );

>Well I want to pass an array that is inside the class, how I do that?
I'm assuming you mean that the array is a member of matrix . In that case, you'd call the function like this:

customMatrix.checkIfMagic( customMatrix.arrayOfArray );

arrayOfArray is a dynamic array create inside a method of the class matrix , so is not in public or private area...

arrayOfArray is a dynamic array create inside a method of the class matrix , so is not in public or private area...

If it was created inside a member function, then the pointer is a local variable (even if the data isn't) and thus you'll lose the address of the data outside of the function. Either you need to declare arrayOfArray as a public/private member of matrix , or you need a pointer to it that is accessible within the scope of ManiMatrix().

If it was created inside a member function, then the pointer is a local variable (even if the data isn't) and thus you'll lose the address of the data outside of the function. Either you need to declare arrayOfArray as a public/private member of matrix , or you need a pointer to it that is accessible within the scope of ManiMatrix().

Yes you are right when the function end, the local variables are destructed. For other side, I can't not put it in public/private arrayOfArray. I think that I will call the method inside the method. Might you explain how to put a pointer to the scope of that method?

>Might you explain how to put a pointer to the scope of that method?
I don't know the details of your program, so I can't really be very specific. Basically you would create a pointer of type int ** somewhere in your program. Then set this pointer to the address of arrayOfArray . Where you declare this pointer is completely up to you, but it has to be in the scope of the method that you allocate arrayOfArray (or else you wouldn't be able to set the pointer to the array) and it has to be in the scope of ManiMatrix (otherwise the purpose of the pointer would be defeated). I'll leave the rest up to you.

>Might you explain how to put a pointer to the scope of that method?
I don't know the details of your program, so I can't really be very specific. Basically you would create a pointer of type int ** somewhere in your program. Then set this pointer to the address of arrayOfArray . Where you declare this pointer is completely up to you, but it has to be in the scope of the method that you allocate arrayOfArray (or else you wouldn't be able to set the pointer to the array) and it has to be in the scope of ManiMatrix (otherwise the purpose of the pointer would be defeated). I'll leave the rest up to you.

ok.. thanks for the advice!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.