Hello, im manuel, new on this forum and new with c++. im having some problems with a project, hope someone can help me:
Usuario::Usuario() its call at "template<class T> class Nodo" line 14 but i dont know why. I have not even creat that constructor so this problem appears:
C:\Documents and Settings\user\Escritorio\TP1\scr\Nodo.h no matching function for call to `Usuario::Usuario()'
void insertar(T dato, Nodo<T>* anterior, Nodo<T>* siguiente) {
/* crea el nodo */
Nodo<T>* nuevo = new Nodo<T>(dato);// HERE ITS THE PROBLEM
nuevo->setAnterior(anterior);
nuevo->setSiguiente(siguiente);
/* actualiza los nodos anterior y siguiente */
if (anterior != NULL) {
anterior->setSiguiente(nuevo);
} else {
/* actualiza el primero en caso de insertar al comienzo */
this->getLista()->setPrimero(nuevo);
}
if (siguiente != NULL) {
siguiente->setAnterior(nuevo);
} else {
/* actualiza el último en caso de insertar al final */
this->getLista()->setUltimo(nuevo);
}
/* se queda en la posición que insertó */
this->setActual(nuevo);
}
NODO & CONSTRUCTOR:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
template<class T> class Nodo {
private:
T dato;
Nodo<T>* siguiente;
Nodo<T>* anterior;
public:
Nodo(T dato) { //This line calls Usuario::Usuario() can't understand why is it call.
this->setDato(dato);
this->setSiguiente(NULL);
this->setAnterior(NULL);
}
Nodo(T d) : dato(d) { //This line calls a constructor for dato. in this case dato(const dato &) T (const T&)
// this->setDato(dato);
this->setSiguiente(NULL);
this->setAnterior(NULL);
}
With the initializer list you call the constructors of your members. If you don't use it, the default constructor is invoked
guestgulkan wrote:
(because if you try to make a node using the Usuario class like this: Nodo<Usaurio> myNode;
The point is that he can't construct a Nodo in that way, because Nodo doesn't have a default constructor.
void agregarUsuario(string nombre); To which class this method belongs?