2017-09-15 52 views
0

我试图实例形状的名单如下:C++的LinkedList的自定义类错误

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

使用this LinkedList的库。我的Arduino使用Platformio进行编译和上传。

当我尝试编译该程序时,我不断收到错误。我手边没有任何标志。我不认为LinkedList库有什么问题,因为它可以很好地使用我使用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 
+0

它需要一个默认的构造函数'Shape()',但是你只有一个构造函数,它需要驱动'Shape(Drive *)'。你需要添加一个'Shape()'构造函数,它不需要参数 –

+0

@SteveLorimer,它可以修复它,哇,我是一个白痴。平心而论,C++并不是我的强项。 – Drew

回答

0

简单的修复,我是愚蠢的。我需要一个默认的构造函数:

在我的Shape.hShape();到我的公共职能。