0

How I can access to a public member function that belongs from another class in c++?

I have two separate files, one file has one class called Matrix with one public member function called void matrixOperators (). I have another class called Menu, with one public member function called void setMenu(). The thing is that in the function setMenu () i want to use the function matrixOperator (), but I got the error: "matrix Operation() was not declared I this scope. I'm still learning OOP, dunno how to fix this problem, do I need to use inheritance? Or what can I do to access to a function that belongs to another class?

19th Jan 2019, 6:32 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
3 Antworten
+ 3
Well, to use a class' method, you must instantiate an object of that class. Matrix m; m.matrixOperation(); Or: if the method is static, you have do the following: Matrix::matrixOperation();
19th Jan 2019, 8:29 AM
voidneo
+ 4
Depending on how the setMenu works and what it does, you have the option to add parameter in setMenu that accepts a Matrix instance object, the setMenu calls matrixOperation from the object passed as method argument. P.S. Since we don't know what the code does (you didn't show the code) I'm not even sure if this is feasible or suitable for the purpose and needs, simply ignore if so.
22nd Jan 2019, 5:56 AM
Ipang
0
neo.h thx! :)
21st Jan 2019, 11:03 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar