Please consider the below scenario:
I have a header file and its corresponding source file:
exmp.h (Header file)
exmp.cpp (Source file)
In the header file I have a function declaration bubSort(...) whose definition is present in
exmp.cpp
myClass::bubSort(...)
{
....
....
}
Where, myClass-> is a class defined in exmp.h
Now in order to use the function bubSort(...) in another file Sample.cpp, I have declared myClass inside Sample.h as shown below:
/*Sample.h*/
class myClass;
class sampleClass
{
.....
.....
myClass *ptr;
};
Now using the above ptr, I'm trying to access bubSort(...) in Sample.cpp as shown below:
//Sample.cpp
#include "exmp.h"
sampleClass::func(...)
{
....
....
ptr->bubSort(...);
}
The above scenario doesn't give any error during compilation, However while execution, when the control reaches ptr->bubSort(...);, I get an exception:
Access violation reading location 0xcdcdcdcd
Would anyone tell how I can avoid this?
Thanks in advance.