Recursive data structure error in mex compiling of object-oriented program

3 次查看(过去 30 天)
I am attempting to use Matlab Coder to build a mex function. The function itself is the front end for an object oriented program. I'm getting a compiling error and can reproduce it with a simple toy example.
The following example compiles and executes without errors. It consists of three files: the main function, an example parent class, and an example child class:
function str = main
M = ParentClass;
str = 'Done';
end
...
classdef ParentClass < handle
properties
Child;
end
methods
function self = ParentClass
self.Child = ChildClass;
end
end
end
...
classdef ChildClass < handle
properties
end
methods
function self = ChildClass
end
end
end
I'd like the child to keep a reference to its parent as a property, which is key for many design patterns. However, this causes a compiling error. I implement it by modifying the two classdefs as shown below. When the parent creates the child, the child stores the parent during the constructor.
classdef ParentClass < handle
properties
Child;
end
methods
function self = ParentClass
self.Child = ChildClass(self); % Line with the compiling error
end
end
end
...
classdef ChildClass < handle
properties
Parent
end
methods
function self = ChildClass(Parent)
self.Parent = Parent;
end
end
end
This produces the coder compiling error "This expression and its property 'Parent.Child' have the same class. Code generation does not support recursive data structures."
Is there a simple way around this language limitation? It works fine in the regular matlab environment, and this behavior is supported in other languages.
edit: Essentially, I'm looking for a way for the Child and Parent to have a reference to each other that is compatible with Matlab Coder.
Thanks in advance for the help
  1 个评论
Dominik Müller
Dominik Müller 2020-11-9
编辑:Dominik Müller 2020-11-10
Hi,
I know the question is already sth like 4 years old but is there an answer on this topic? I'm stuck to the same problem right now.

请先登录,再进行评论。

回答(1 个)

Darshan Ramakant Bhat
Unfortunately MATLAB Coder does not support recursive data structures yet. It is documented in the below page :
We have made an internal request to support this in one of the future releases.

类别

Help CenterFile Exchange 中查找有关 MATLAB Code Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by