Ich brauche eine nicht statische Elementfunktion von einer nicht statischen Elementfunktion der gleichen Klasse nennen wie:Wie non-static Elementfunktion von einer statischen Elementfunktion aufgerufen wird?
class bintree {
private:
float root;
bintree *left;
bintree *right;
public:
bintree() : left(nullptr), right(nullptr) {
}
bintree(const float &t) : root(t), left(nullptr), right(nullptr) {
}
~bintree() {
if (left != nullptr)
delete left;
if (right != nullptr)
delete right;
}
static void niveles(bintree *);
static bintree *dameBST(float** array, int depth, int left = 0, int right = -1);
void quickSort2D(float** arr, int left, int right, int n);
};
Mein Problem ist in dameBST Funktion, wenn ich die quickSort2D das Programm Crush mit ‚Segmentation fault nennen: 11 'Nachricht.
bintree *
bintree::dameBST(float **array, int depth, int left, int right)
{
int n=0;
depth++;
bintree *t = new bintree;
bintree *tl;
bintree *tr;
if(depth%2 != 0) { n = 1; }
quickSort2D(array, left, right -1, n);
if (right == -1) {right = 10;}
if (left == right) { return nullptr; }
if(left == right - 1) { return new bintree(array[left][n]); }
int med = (left + right)/2;
t->root = array[med][n];
tl = dameBST(array, depth, left, med);
tr = dameBST(array, depth, med + 1, right);
t->left = tl;
t->right = tr;
return t;
Ich verstehe nicht warum.
Sie nicht:), wenn Sie das tun müssen, bedeutet das, dass die statische Funktion in erster Linie eine Elementfunktion sein muss. – alfC
Nun, ich denke, die klassische Antwort wäre, die Instanz als Parameter zu übergeben und dann die Instanzmethode aus der statischen Funktion heraus aufzurufen. –