#include <iostream>
using namespace std;
class Widget {
public:
int width;
virtual void resize() { width = 10; }
};
class SpeWidget :public Widget {
public:
int height;
void resize() override {
//Widget::resize();
Widget* th = static_cast<Widget*>(this);
th->resize();
height = 11;
}
};
int main() {
//Widget* w = new Widget;
//w->resize();
//std::cout << w->width << std::endl;
SpeWidget* s = new SpeWidget;
s->resize();
std::cout << s->height << "," << s->width << std::endl;
std::cin.get();
}
Derived class (SpeWidget) virtual function (resize()) wants to call that in base class (Widget). Why does the above code have segment fault. Thank you!