Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Rollback to Revision 1
Source Link
Blob
  • 579
  • 1
  • 6
  • 19

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived : public Base { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); } 

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); } 

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived : public Base { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); } 
deleted 14 characters in body
Source Link
Blob
  • 579
  • 1
  • 6
  • 19

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived : public Base { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); } 

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived : public Base { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); } 

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); } 
Source Link
Blob
  • 579
  • 1
  • 6
  • 19

The pointer p had to be used. Other than that, you could write any additional code, including as many classes as necessary to insure that the "bar()" method was called using the object pointed to by p.

As many classes as necessary, you say?

#include <iostream> class Base { public: void foo() { std::cout << "foo" << std::endl; } }; class Derived : public Base { public: void bar() { std::cout << "bar" << std::endl; } }; int main() { class Base { public: void bar() { std::cout << "bar" << std::endl; } }; class Derived : public Base { }; Base *p = new Derived; p->bar(); }