我收到了这个错误:
Lista.h: In instantiation of 'Lista<X>::Lista(const Lista<X>&) [with X = ArbolN<int>]': main.cpp:22:20: required from here
Lista.h:50:5: error: no matching function for call to 'ArbolN<int>::ArbolN(ArbolN<int>)'
l = new Nodo<X> (list.l->getInfo(), NULL);
^
使用此代码:
#include <iostream>
#include "ArbolN.h"
using namespace std;
int main()
{
Lista<ArbolN<int> > L;
ArbolN<int> A(1), B(2);
ArbolN<int> C(3);
L.insertar( 1 , A);
L.insertar( 2 , B);
L.insertar( 3 , C);
ArbolN<int> D(5, L); //this is main.cpp: 22
}
//第一个参数是根的值,第二个列表是儿子
//constructor
template <class X>
ArbolN<X>::ArbolN(X e,Lista<ArbolN<X> > h){
NodoAr<X> *aux;
raiz= new NodoAr<X>(e);
if(!h.esVacia()){
//tmp = new NodoAr<X>(l.consultar(1));
copiarNodos(h.consultar(1).raiz,raiz->HijI);
h.eliminar(1);
aux=raiz->HijI;
while(!h.esVacia()){
copiarNodos(h.consultar(1).raiz,aux->HerD);
h.eliminar(1);
aux=aux->HerD;
}//while
}//if
}
//copy constructor
//constructor copia
template <class X>
ArbolN<X>::ArbolN(ArbolN<X> &Ar){
if(Ar.raiz){
copiarNodos(Ar.raiz,raiz);
}else{
raiz=NULL;
}
}
template <class X>
void ArbolN<X>::copiarNodos(NodoAr<X> *orig,NodoAr<X> *&dest){
NodoAr<X> *a(NULL),*b(NULL);
if (orig != NULL){
dest=new NodoAr<X>(orig->info);
copiarNodos(orig->HijI,dest->HijI);
if((orig->HerD==NULL)&&(orig->HijI!=NULL)){
a=orig->HijI;
b=dest->HijI;
}else{
a=orig;
b=dest;
}
while(a!=NULL){
a=a->HerD;
copiarNodos(a,b->HerD);
b=b->HerD;
}
}
else dest = NULL;
}
有人可以告诉我我做错了什么,我不知道为什么在该部分代码中需要lista.h