0

我正在尝试实例化这样的形状列表:

LinkedList<Shape> *shapes = new LinkedList<Shape>();

使用这个LinkedList 库。对于我的 Arduino,使用 Platformio 编译和上传。

当我尝试编译程序时,我不断收到错误。我事先没有得到任何标志。我认为 LinkedList 库没有任何问题,因为它与我使用的 struct 配合得很好POS。问题似乎出在Shape::Shape(...)构造函数上。

这应该不重要,但是,Shape该类是一个简单的父类,允许Shape在单个列表中混合特定的子类:CircleEllipseLine等。

// POS
struct POS {
    int x;
    int y;
};

// Shape.h
#ifndef SHAPE_H
#define SHAPE_H
#include "../stepper/POS.h"
#include "../Drive.h"

class Drive;

class Shape {
public:
    Drive *_drive;
    Shape(Drive *drive);
    ~Shape();

    POS draw();
};

#endif

//Shape.cpp
#include "Shape.h"

class Drive;

Shape::Shape(Drive *drive): _drive(drive){};

Shape::~Shape() {
    delete _drive;
};

POS Shape::draw(){
    return _drive->get();
};

错误:

[Thu Sep 14 19:51:04 2017] Processing uno (platform: atmelavr; lib_deps: LinkedList; board: uno; framework: arduino)

--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 25 compatible libraries
Looking for dependencies...
Library Dependency Graph
|-- <LinkedList>
|-- <Servo> v1.1.2
Compiling .pioenvs/uno/src/Project/main.o
In file included from src/Project/main.cpp:4:0:
.piolibdeps/LinkedList_ID443/LinkedList.h: In instantiation of 'bool LinkedList<T>::add(int, T) [with T = Shape]':
src/Project/main.cpp:50:1:   required from here
.piolibdeps/LinkedList_ID443/LinkedList.h:184:37: error: use of deleted function 'ListNode<Shape>::ListNode()'
ListNode<T> *tmp = new ListNode<T>(),
^
.piolibdeps/LinkedList_ID443/LinkedList.h:19:8: note: 'ListNode<Shape>::ListNode()' is implicitly deleted because the default definition would be ill-formed:
struct ListNode
^
.piolibdeps/LinkedList_ID443/LinkedList.h:19:8: error: no matching function for call to 'Shape::Shape()'
.piolibdeps/LinkedList_ID443/LinkedList.h:19:8: note: candidates are:
In file included from src/Project/shapes/Circle.h:3:0,
from src/Project/main.cpp:7:
src/Project/shapes/./Shape.h:11:5: note: Shape::Shape(Drive*)
Shape(Drive *drive);
^
src/Project/shapes/./Shape.h:11:5: note:   candidate expects 1 argument, 0 provided
src/Project/shapes/./Shape.h:8:7: note: constexpr Shape::Shape(const Shape&)
class Shape {
^
src/Project/shapes/./Shape.h:8:7: note:   candidate expects 1 argument, 0 provided
In file included from src/Project/main.cpp:4:0:
.piolibdeps/LinkedList_ID443/LinkedList.h: In instantiation of 'bool LinkedList<T>::add(T) [with T = Shape]':
src/Project/main.cpp:50:1:   required from here
.piolibdeps/LinkedList_ID443/LinkedList.h:199:37: error: use of deleted function 'ListNode<Shape>::ListNode()'
ListNode<T> *tmp = new ListNode<T>();
^
.piolibdeps/LinkedList_ID443/LinkedList.h: In instantiation of 'bool LinkedList<T>::unshift(T) [with T = Shape]':
src/Project/main.cpp:50:1:   required from here
.piolibdeps/LinkedList_ID443/LinkedList.h:225:37: error: use of deleted function 'ListNode<Shape>::ListNode()'
ListNode<T> *tmp = new ListNode<T>();
^
Linter
Severity    Provider    Description Line 
PIO Buildsrc/Project/shapes/Shape.cpp00011:19
LFUTF-8C++master+141 update
4

1 回答 1

1

简单的解决方法,我是愚蠢的。我需要有一个默认构造函数:

在我Shape.h添加Shape();到我的公共功能中。

于 2017-09-15T02:05:30.097 回答