Как в указатель родителя сохранить указатель потомка? Новый комментарий Nextor 2021.09.03 23:54 Добрый день.Как MQL5 объявить общий для всех потомков массив указателей?Нужно чтоб в массиве были как родители, так и потомки.Приведенный ниже код не работает.... class TestParent { private: int a; int b; public: TestParent() {}; TestParent(int c, int d) {a = c; b = d;}; double Multi(void){return a * b;}; ~TestParent() {}; }; class TestChild: public TestParent { private: int f; public: TestChild() {}; TestChild(int g) {f = g;}; ~TestChild() {}; double Sum(double r){return r + f;}; }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { TestParent * TestArray[4]; TestArray[0] = new TestParent(1,2); TestArray[1] = new TestChild(3); //Здесь прокатывает double res = TestArray[0].Multi(); double res2 = TestArray[1].Sum(5); //А здесь ошибка! } Если наоборот то тоже ошибка: void OnStart() { TestChild * TestArray[4]; TestArray[0] = new TestParent(1,2); //Ошибка Incorrect custings of pointers TestArray[1] = new TestChild(3); double res = TestArray[0].Multi(); double res2 = TestArray[1].Sum(5); } fxsaber 2021.09.04 00:09 #1 ((TestChild*)TestArray[1]).Sum(5) Nextor 2021.09.04 00:32 #2 fxsaber #: Спасибо Новый комментарий
Как MQL5 объявить общий для всех потомков массив указателей?
Нужно чтоб в массиве были как родители, так и потомки.
Приведенный ниже код не работает....