M
Marcelo
Hi everybody,
I don't understand why I am having a problem in this code.
The problem is that my pointer *phist in main method, it is declared.
Then I send the pointer to my method, and this method creates a new object (a
Matrix) for it.
I suppose that after the new operator, my pointer is pointing to an object, so
when the method has finished, the very first pointer is still poitint to the
created method; however this is not working, I have a message as if the pointer
hasn't been initialized...
Do you have an idea?
thanks a lot for your help,
Marcelo
------
int main(){
Matrix<uchar> *mgrey;
mgrey = new Matrix<uchar>(5,5);
for(unsigned i=0; i < (*mgrey).getH() * (*mgrey).getW(); i++){
*((*mgrey).val + i) = i*10;
}
Matrix<float> *phist;
Matrix<uchar> *mtest;
//here i send my pointer
mtest = method(phist, mgrey);
//my pointer has not been initialized...
printf("%d ",(*phist).size());
}
Matrix<float>* method(Matrix<float> *ptr, Matrix<uchar> *mgrey){
..blah ...blah
ptr = new Matrix<float>(3,3);
blah..blah
return 0;
}
I don't understand why I am having a problem in this code.
The problem is that my pointer *phist in main method, it is declared.
Then I send the pointer to my method, and this method creates a new object (a
Matrix) for it.
I suppose that after the new operator, my pointer is pointing to an object, so
when the method has finished, the very first pointer is still poitint to the
created method; however this is not working, I have a message as if the pointer
hasn't been initialized...
Do you have an idea?
thanks a lot for your help,
Marcelo
------
int main(){
Matrix<uchar> *mgrey;
mgrey = new Matrix<uchar>(5,5);
for(unsigned i=0; i < (*mgrey).getH() * (*mgrey).getW(); i++){
*((*mgrey).val + i) = i*10;
}
Matrix<float> *phist;
Matrix<uchar> *mtest;
//here i send my pointer
mtest = method(phist, mgrey);
//my pointer has not been initialized...
printf("%d ",(*phist).size());
}
Matrix<float>* method(Matrix<float> *ptr, Matrix<uchar> *mgrey){
..blah ...blah
ptr = new Matrix<float>(3,3);
blah..blah
return 0;
}