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?
3 Answers
+ 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();
+ 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.
0
neo.h thx! :)