Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Arduino:指针子类的继承和数组_C++_Inheritance_Arduino - Fatal编程技术网

C++ Arduino:指针子类的继承和数组

C++ Arduino:指针子类的继承和数组,c++,inheritance,arduino,C++,Inheritance,Arduino,这是前一个问题中的问题#2: 根据Steven的答案,我确实需要一个数组,它将指针保存在它的范围之外,这会导致一些奇怪的行为 这是我迄今为止的“Board”类,它包含多个子元素: 董事会h: #ifndef Board_h #define Board_h #include <StandardCplusplus.h> #include <serstream> #include <string> #include <vector> #include

这是前一个问题中的问题#2:

根据Steven的答案,我确实需要一个数组,它将指针保存在它的范围之外,这会导致一些奇怪的行为

这是我迄今为止的“Board”类,它包含多个子元素:

董事会h:

#ifndef Board_h
#define Board_h

#include <StandardCplusplus.h>
#include <serstream>
#include <string>
#include <vector>
#include <iterator>

#include "Arduino.h"
#include "Marble.h"
#include "Wall.h"

class Board
{
  public:
    Board();
    void draw(double* matrix);
  private:
    Marble marble;
    //std::vector<Actor> children;
    Actor* children[2];

};
#endif
这会导致一些疯狂的串行代码被写出来


显然,我不理解这里类中数组中指针的输入和输出。

您需要使
Actor::speak
虚拟,编译器对虚拟方法使用动态绑定

class Actor
{
  public:
    Actor();
    virtual void speak();  // virtual
  private:
};

循环
函数中,什么是
矩阵
大理石
参与者
的子类?大理石::说话是虚拟的吗?
Actor::speak
是虚拟的吗?如果这三个问题的答案都是肯定的,那么代码应该可以工作。
board.draw(matrix);
class Actor
{
  public:
    Actor();
    virtual void speak();  // virtual
  private:
};