Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
inheritance
:
Content language: Русский
English
Что выведет программа? #include <iostream> #include <exception> using namespace std; class a { public: virtual void f(int) { cout<<"a int"; } virtual void f(char*) { cout<<"a char*"; } }; class b : public a { public: virtual void f(char*) { cout<<"b char*"; } }; int main (void) { b* o = new b; o->f(0); return 0; }
inheritance
Что выведет на консоль следующая программа? #include <iostream> using namespace std; struct A { virtual void print(int x = 0) const { cout << x; } }; struct B: public A { virtual void print(int x = 3) const { A::print(x); } }; int main() { A* pa = new A; pa->print(); A* pb = new B; pb->print(); A a; a.print(); B b; b.print(); return 0; }
inheritance
В каких строчках содержатся ошибки? struct A { virtual void Foo(int) {} virtual void Foo(int, int) {} void Foo(int, int, int) {} }; struct B : A { virtual void Foo(int) {} }; int main() { B b; b.Foo(1); // 1 b.Foo(1, 2); // 2 b.Foo(1, 2, 3); // 3 }
inheritance
Что выведется при выполнении программы: class A { protected: virtual void v() = 0; public: void f() { std::cout << "A::f()" << std::endl; this->v(); } protected: A() { std::cout << "A::A()" << std::endl; this->f(); } }; class B: public A { private: virtual void v() { std::cout << "B::v()" << std::endl; } }; int main() { A *pa = new B; pa->f(); return 0; }
inheritance
Что бyдет напечано? #include <iostream> struct Car { Car() : price(20000) {} Car(double b) : price(b*1.1) {} double price; }; struct Toyota : public virtual Car { Toyota(double b) : Car(b) {} }; struct Prius : public Toyota { Prius(double b) : Toyota(b) {} }; int main(int argc, char** argv) { Prius p(30000); std::cout << p.price << std::endl; return 0; }
inheritance
Что будет напечатано в результате работы программы? #include <iostream> class A { private: virtual void VirtualMethod() { std::cout << "A::VirtualMethod()"; } public: void TestMethod() { VirtualMethod(); } virtual ~A() {} }; class B : public A { private: void VirtualMethod() { std::cout << "B::VirtualMethod()"; } public: ~B() {} }; int main() { A* a = new B(); a->TestMethod(); delete a; return 0; }
inheritance
Что выведет следующий код: struct A { ~A() { std::cout << "~A()"; } }; struct B : A { ~B() { std::cout << "~B()"; } }; struct C : B { ~C() { std::cout << "~C()"; } }; int main() { std::shared_ptr<A> p(false ? new B() : new C()); return 0; }
inheritance
Что будет выведено на экран в результате выполнения такого кода: #include <iostream> struct A { ~A() { std::cout << "~A"; }; }; struct B: public A { virtual ~B() { std::cout << "~B"; }; }; int main() { A *a = new B(); delete a; return 0; }
inheritance
Что будет выведено на консоль в результате выполнения программы? #include <iostream> struct A { char foo() { return 'A';} }; template<class T> struct B : public T { virtual char foo() {return 'B';} }; template<class T> struct C : public T { virtual char foo() {return 'C';} }; int main(int argc, char* argv[]) { A* a = new A(); A* b = new B< A >(); A* c = new C< A >(); A* d = new B< C< A > >(); std::cout << a->foo() << b->foo() << c->foo() << d->foo(); return 0; }
inheritance
Что будет выведено на экран при выполнении следующего кода: #include <iostream> template<class T>struct Counter { Counter() { ++count; } static int count; }; template<class T> int Counter<T>::count = 0; struct Derived1: Counter<Derived1> {}; struct Derived2: Counter<Derived2> {}; int main(int argc, char** argv) { Derived1 a, b; Derived2 c; std::cout << Derived1::count << Derived2::count << '\n'; return 0; }
inheritance
← Prev
2
3
4
5
6
Next →
Sign Up Now
or
Subscribe for future quizzes