Class method calls method of other instantiated class
Show older comments
Hello everyone,
I'm new to OOP and have a question.
I have the following class:
classdef Operator
properties
id;
offer;
end
methods
% Functions
function submitOffer(obj)
% submit offer
centralMarket.enterOffer(obj.offer);
end
end
An instance of this class shall pass the variable "offer" to an instance of the class "CentralMarket".
classdef CentralMarket
properties
id;
orderBook;
marketResult;
end
% Functions
function obj = enterOffer(obj, offer)
% write offer into the order book
w_idx = length(obj.orderBook) + 1;
obj.orderBook{w_idx} = offer;
end
For this I call the function "submitOffer" of the initialized class "Operator":
operator.submitOffer();
But it's not working out the way I want it to. I get the following message:
Undefined variable "centralMarket" or class "centralMarket.enterOffer".
Of course, I can work around the whole thing as follows:
centralMarket = centralMarket.enterOffer(operator.offer);
But that wouldn't be pleasant. Is there a way?
Accepted Answer
More Answers (0)
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!