Recursive data structure error in mex compiling of object-oriented program
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Dominik Müller
el 9 de Nov. de 2020
Editada: Dominik Müller
el 10 de Nov. de 2020
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.
Respuestas (1)
Darshan Ramakant Bhat
el 10 de Nov. de 2020
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.
0 comentarios
Ver también
Categorías
Más información sobre MATLAB Code Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!