2017-09-15 2 views
0

Je suis en train de instancier une liste des formes comme ceci:C++ LinkedList des classes personnalisées erreur

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

aide this bibliothèque LinkedList. Pour mon Arduino en utilisant Platformio pour compiler et télécharger.

Je continue d'obtenir des erreurs lorsque j'essaie de compiler le programme. Je n'ai pas de drapeaux avant la main. Je ne pense pas qu'il y ait quelque chose de mal avec la bibliothèque LinkedList car cela fonctionne très bien avec une structure que j'utilise POS. Le problème semble être lié au constructeur Shape::Shape(...).

Il ne devrait pas être important, mais la classe Shape est une simple classe parent pour permettre le mélange des Shape spécifiques des enfants dans une seule liste: Circle, Ellipse, Line, etc.

// 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(); 
}; 

Erreur:

[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

Il a besoin d'un constructeur par défaut 'Shape()', mais vous n'avez qu'un constructeur qui prend un disque 'Shape (Drive *)'. Vous devez ajouter un constructeur 'Shape()' qui ne prend aucun paramètre –

+0

@SteveLorimer, yup, qui l'a corrigé, wow je suis un idiot. En toute justice, le C++ n'est pas mon fort. – Drew

Répondre

0

Correction simple, j'étais stupide. Je dois avoir un constructeur par défaut:

dans mon Shape.h ajouter Shape(); à mes fonctions publiques.