I'm getting this error when compiling:
error C2270: 'busco' : modifiers not allowed on nonmember functions
I think I understand the reason but I don't know how to fix it, if I take the const
out I get a C2662 error.
Here is the code:
template <class T>
class ABBImp: public ABB<T> {
public:
const T& Recuperar(const T &e) const ;
private:
NodoABB<T> * busco(NodoABB<T> * arbol,T &e) const;
protected:
NodoABB<T>* arbol;
};
template <class T>
//If I take this const out I get the other error I talked about
NodoABB<T>* busco(NodoABB<T> * arbol,T &e)const{
if(a!=NULL){
if(arbol->dato==e)
return arbol;
else if (arbol->dato<e)
return busco(arbol->der,e);
else
return busco(arbol->izq,e);
}else{
return NULL;
}
}
template <class T>
const T& ABBImp<T>::Recuperar(const T &e) const{
NodoABB<T> * aux=busco(arbol,e);
return aux->dato;
}
Thanks!
You have an error C2270 because your busco
function is a free template function, it does not belong to a class. So const
makes no sense on the signature : remove it.
If you intended this function to be a member function, place its definition at the point of declaration (I guess the ABBImp
class), or prefix the declaration with the class name as you did for the Recuperar
function.