I have the following problem. I have a class that has declared a virtual function. When I call the virtual function I get an access violation with the code 0xC0000005. Here is an example program so that you can understand the problem
My header
#include <iostream>
class Test{
public:
virtual void display(int* i);
int run();
};
My cpp
int Test::run{
int a = 3;
int *ptrA = &a;
display(ptrA);
if(*ptrA>2){//Here I get my access violation message
enter code here
}
return 1;
}
void Test::display(int* i){
std::cout<< *i;
}
And my Main
int main() {
Test t;
t.run();
}
When I execute the display function, I get the access violation error message. If I remove the function then it works and if I remove virtual from the function display
it also works. The function is not implemented anywhere else.
For this reason I do not understand why I get this error message.