11/10 14:00
Thejuster
Salve ragazzi,
Sto cercando di creare un template paragonabile ad una lista generica,
Ma ho un errore quando provo ad inizializzare il costruttore o la lista stessa.
Quello che vorrei fare è avere una lista basata su questa classe
1) Classe Rectangle
2) Un Template di una lista generica
Nel codice esempio come provo a scrivere
Ho un errore del genere:
error: no matching function for call to 'Rectangle::Rectangle()'
Aiuti su come posso risolvere?
Sto cercando di creare un template paragonabile ad una lista generica,
Ma ho un errore quando provo ad inizializzare il costruttore o la lista stessa.
Quello che vorrei fare è avere una lista basata su questa classe
1) Classe Rectangle
#ifndef RECTANGLE_H #define RECTANGLE_H class Rectangle { public: int X; int Y; int Width; int Height; Rectangle(int x,int y,int width,int height) : X(x),Y(y),Width(width),Height(height){} //Costruttore Rectangle(const Rectangle& o) { X = o.X; Y = o.Y; Width = o.Width; Height = o.Height; } Rectangle& operator =(const Rectangle& o) { if(this != &other) { X = o.X; Y = o.Y; Width = o.Width; Height = o.Height; } return *this; } }; #endif // RECTANGLE_H
2) Un Template di una lista generica
template <class T> class List { T values [100000]; private: int count = 0; public: void Add(T value) { values[count] = value; count++; } int Count() { return count; } T& operator [](int idx) { return values[idx]; } T& operator ++ (int idx) { values[idx]++; } T& operator -- (int idx) { values[idx]--; } bool Contains(T key) { for(int i = 0; i < sizeof(values); i++) { if(key == values[i]) return true; } } };
Nel codice esempio come provo a scrivere
List<Rectangle> *re = new List<Rectangle>; //oppure List<Rectangle> re;
Ho un errore del genere:
error: no matching function for call to 'Rectangle::Rectangle()'
Aiuti su come posso risolvere?
mire.forumfree.it/ - Mire Engine
C# UI Designer
C# UI Designer