Last active
December 28, 2015 16:09
-
-
Save ffedoroff/7527407 to your computer and use it in GitHub Desktop.
arduino trouble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BaseSensor sensors[] = { | |
| SonicSensor ("s0", 13, 12, 55, 5000, 0), | |
| SonicSensor ("s1", 11, 55, 5000, 0), | |
| SonicSensor ("s2", 10, 55, 5000, 0), | |
| SonicSensor ("s3", 9, 45, 5000, 0), | |
| ButtonSensor ("b01", 8, 10, 100, 0), | |
| ButtonSensor ("b02", 7, 10, 100, 0), | |
| BoolSensor ("m1", 6, 5000, 0), | |
| BoolSensor ("m2", 5, 5000, 0), | |
| BoolSensor ("m3", 4, 5000, 0), | |
| BoolSensor ("m4", 3, 5000, 0), | |
| }; | |
| sensors[2].init(); // ОШИБКА! вызывается метод init не у наследника (SonicSensor), а у базового класса (BaseSensor) | |
| // но если попробовать объявить | |
| SonicSensor obj_b("tmp", 12, 1, 2, 3); | |
| BaseSensor &obj_a = obj_b; | |
| obj_a.init(); // ТУТ ВСЕ ПРАВИЛЬНО. Вызывается метод init у наследника (SonicSensor), а не у базового класса (BaseSensor) | |
| // ВОПРОС - как мне красиво в массиве инициализировать всех наследников? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment