I am to convert some custom data structures into float** and pass them as arguments of a method that is dealing with float** only.
In my first version, method takes only 2 float** as arguments, so that i easily have
MyClass::MyMethod(float** data1, float** data2){}
In a second version, I would like to vehicle a list of float** with length varying from one execution to the next.
I only have float*** as a solution, which is not nice at all.
MyMethod is C-stylish, I don’t want any vector, etc…
Other ideas?
Thanks
Return a struct containing some float**. You could even pass in an instance of the struct.
It means that the called function doesn’t directly manipulate the caller’s float** which I think is cleaner.
We’re solving this as C programmers, I understand that sometimes we’re constrained not to use true C++ techniques.
If you have (apologies for any syntax errors it’s years since I wrote C)
Your interface now can be
the implementation of myMethod can work with the float** from the input FloatCarrier. If it needs to modify the arrays then it creates a new FloatCarrier with new float** instances and when it has finished it returns the new FloatCarrier. This does put some responsibility with the caller to grab the new float** from the returned struct, but somehow I like that, feels cleaner.
As to whether you should have a known number of members or an array … well your example had exactly 2 parameters, so the struct would have two members, but you can have an array or anything you like.
How does it solve your problem: you no longer need to change your caller’s float** hence no float***. We use a struct as a function can return only one value, so we package up the results into a single object.