2017-09-15 81 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();到我的公共職能。