Question: 3. a) Why is only the TokenD :: foo () method called? b) Why a TokenB class destroyer is called, but also TokenD class destructor?
3. a) Why is only the TokenD :: foo () method called? b) Why a TokenB class destroyer is called, but also TokenD class destructor? (C++)
1 #include
3class TokenB { 4 public: 5 virtual void foo() { std::cout << "TokenB::foo()"; } 6 virtual ~TokenB() { std::cout << "~TokenB()"; }; 7 }; 8
9class TokenD : public TokenB { 10 public: 11 void foo() override { std::cout << "TokenD::foo()"; } 12 ~TokenD() override { std::cout << "~TokenD()"; }; 13 }; 14 15 int main() { 16 TokenB* t0 = static_cast
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
