The teacher asked the question, in which line of this code (C ++) is static polymorphism implemented? Also, the teacher said that there exists a static polymorphism implicitly.

#include"stdafx.h" #include<iostream> #include<clocale> #include<conio.h> #include<ctime> using namespace std; class pulsometer { public: int pulse; int calories; int timer; void show_pulse(void); void show_calories(void); void show_timer() { cout << "Таймер: " << timer << endl; } void start_timer() { timer = 10; } }; void pulsometer::show_pulse(void) { pulsometer::pulse = rand() % 45 + 90; cout << "Пульс: " << pulse << endl; } void pulsometer::show_calories(void) { pulsometer::calories = rand() % 1000; cout << "Сожжено: " << calories << " ККал" << endl; } int_tmain(intargc, _TCHAR* argv[]) { setlocale(0,""); srand( time( 0 ) ); pulsometer polar; polar.start_timer(); polar.show_timer(); polar.show_pulse(); polar.show_calories(); _getch(); return 0; } 
  • AFAIK in no way, since it will not compile in its current form. But I see that you already know and correct :) - D-side

2 answers 2

There is no polymorphism here: neither static nor dynamic. There is no inheritance, no overloaded functions, no template functions.

Polymorphism means many forms.

Here there is one class - one form. Here there is only static binding of class method calls with an object that has a static type of this class.

  • I also tried to find and did not find - user31238
  • @ program23 Let the teacher take part in discussions on this site. :) We’ll show him "fucking mother." :) - Vlad from Moscow

In all such lines (operator << overloaded): cout << "Таймер: " << timer << endl;

  • This has nothing to do with the definition of a class. - Vlad from Moscow
  • @VladfromMoscow And where is the word "class definition" in question? - Igor