Hi guys,
I've a problem, i've those class, that now works, because i've the attribute in public, but if i put it in private, or protected and inherited to the second class, it's not work, how can i do it?
I need to respect OOP rules
You haven't told us which attributes you're talking about, nor how you're trying to use them that's causing an error, so there's really not a lot we can do to diagnose the problem.
Do you understand the difference between a private and a public member?
Yes,
but i don't know how to create methods for put all attributes (Left, right, parent, and key) privates.
What i must change in BinaryNode and BinarySearchTree Class?
The standard way to do this is to make your data members (i.e. attributes) private, because they're implementation details.
If you need the interface of your class to allow other classes to either get the values of those members, or set them, then you should write get and/or set methods in the public interface of your class. These methods can be called by any other class, because they're in the public interface.
Well, there you go. As I said, you need to write public get/set methods, so that other classes can call those methods to either retrieve the value of an attribute, or to change the value of the attribute.
It's not difficult. Just think about it a little. If someone asked you write a method to return the value of, say, left, how do you think you'd write that?
And for set? BinaryNode<T>* setleft(T l){ left = l; }
it's ok this?
and in the class Binarysearchtree of i must call this?
Example: void insert(BinaryNode<T>** node, T key);
This?
Well, you need to decide exactly what it is you want to allow other classes to do? Do you want them to supply an object of type T by value, to be copied into the position to the left of the node? Or do you want it it to provide a pointer to an existing object? Or do you want to provide a ready-built BinaryNode?
You have to think about how you want the class to work, and how you want other classes to interact with it.
If you were using public data members previously, presumably you already have some ideas about that.
1>c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(20): error C2440: '=': impossibile convertire da 'std::string' a 'BinaryNode<T> *'
1> with
1> [
1> T=std::string
1> ]
1> Nessun operatore di conversione definito dall'utente è disponibile o è impossibile chiamare l'operatore
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(20): durante la compilazione della classe modello, funzione membro 'void BinaryNode<T>::setleft(T)'
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(91): vedere il riferimento all'istanza del modello di funzione 'void BinaryNode<T>::setleft(T)' in corso di compilazione
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(241): vedere il riferimento all'istanza del modello di classe 'BinaryNode<T>' in corso di compilazione
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(237): durante la compilazione della classe modello, funzione membro 'BinaryNode<T> *BinarySearchTree<T>::remove(BinaryNode<T> *)'
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\main.cpp(34): vedere il riferimento all'istanza del modello di funzione 'BinaryNode<T> *BinarySearchTree<T>::remove(BinaryNode<T> *)' in corso di compilazione
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\main.cpp(9): vedere il riferimento all'istanza del modello di classe 'BinarySearchTree<std::string>' in corso di compilazione
========== Compilazione: 0 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========
Ok for setleft (right and parent) it's ok now works,
but for getlefts? it's not works...
It's right this? BinaryNode<T>* getleft(){ return left; }
(same error)
1>------ Inizio compilazione: Progetto: [ASD]Vocabolario, Configurazione: Debug Win32 ------
1> main.cpp
1>c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(124): error C2102: '&' richiede un l-value
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(113): durante la compilazione della classe modello, funzione membro 'void BinarySearchTree<std::string>::insert(BinaryNode<T> **,T)'
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(104): vedere il riferimento all'istanza del modello di funzione 'void BinarySearchTree<std::string>::insert(BinaryNode<T> **,T)' in corso di compilazione
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(103): durante la compilazione della classe modello, funzione membro 'void BinarySearchTree<std::string>::insert(T)'
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\main.cpp(25): vedere il riferimento all'istanza del modello di funzione 'void BinarySearchTree<std::string>::insert(T)' in corso di compilazione
1> with
1> [
1> T=std::string
1> ]
1> c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\main.cpp(9): vedere il riferimento all'istanza del modello di classe 'BinarySearchTree<std::string>' in corso di compilazione
1>c:\users\davide\dropbox\davide\[asd]\progetto\[asd]vocabolario\[asd]vocabolario\classi.h(130): error C2102: '&' richiede un l-value
========== Compilazione: 0 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========
Only this, because this works: (*node)->getright()->parent = *node;