1 | initial version |
having 2 classes with the same name, but a different memory layout in your program is a design desaster. (and the reason for your mysterious segfaults). use interfaces, virtual functions and inheritance instead:
// header:
struct MyProcessing {
virtual ~MyProcessing() {}
virtual bool func1(const Mat &input, Mat &output) = 0;
virtual bool func2(Mat &input) = 0; // modify in-place
private:
MyProcessing() {} // not allowed to use
};
// "factory" function
Ptr<MyProcessing> createMyProcessing();
// implementation:
struct MyProcessingImpl : public MyProcessing {
bool func1(const Mat &input, Mat &output) {
...
}
bool func2(Mat &input) {
...
}
Mat privateData;
int foo;
};
// "factory" function, returns implementation class
Ptr<MyProcessing> createMyProcessing() { return makePtr<MyProcessingImpl>(); }
// usage
Ptr<MyProcessing> process = createMyProcessing();
Mat input = ...
Mat output;
process->func1(input, output);
// no cleanup nessecary
2 | No.2 Revision |
having 2 classes with the same name, but a different memory layout in your program is a design desaster. (and the reason for your mysterious segfaults). use interfaces, virtual functions and inheritance instead:
// public (API) header:
struct MyProcessing {
virtual ~MyProcessing() {}
virtual bool func1(const Mat &input, Mat &output) = 0;
virtual bool func2(Mat &input) = 0; // modify in-place
private:
MyProcessing() {} // not allowed to use
};
// "factory" function
Ptr<MyProcessing> createMyProcessing();
// private implementation:
struct MyProcessingImpl : public MyProcessing {
bool func1(const Mat &input, Mat &output) {
...
}
bool func2(Mat &input) {
...
}
Mat privateData;
int foo;
};
// "factory" function, returns implementation class
Ptr<MyProcessing> createMyProcessing() { return makePtr<MyProcessingImpl>(); }
// usage
Ptr<MyProcessing> process = createMyProcessing();
Mat input = ...
Mat output;
process->func1(input, output);
// no cleanup nessecary