Reputation: 5023
I tried Structure of Mat my app shows as "Run failed". Anyother way to do this?
The below is the code I tried and its getting failed. How to make this workout or anyother ways are there?
"Common.h"
struct initialize {
cv :: Mat G_Sm;
};
"Initialize.cpp"
struct initialize* initfunction ( ) {
struct initialize* initializemat = ( initialize* ) malloc(sizeof(*initializemat));
initializemat -> G_Sm = Mat:: zeros ( 3,1, CV_8U );
return (initializemat);
}
"main.cpp"
int main () {
struct initialize* initializem = initfunction ();
cout << initializem -> G_Sm << endl;
return 0;
}
Instead of Mat if I use "int" the program is not getting crashed. If it is "Mat" variable in the structure the program gets crashed.
Upvotes: 1
Views: 2060
Reputation: 66459
Use C++ instead of C:
initialize* initfunction ( ) {
initialize* initializemat = new initialize;
return initializemat;
}
You shouldn't allocate C++ objects with malloc
.
malloc
doesn't call any constructors for you, leaving G_Sm
uninitialised.
Upvotes: 6