0
class Trie
{
public:
    bool isLeaf;
    Trie* character[CHAR_SIZE];

    // Constructor
    Trie()
    {
        this->isLeaf = false;

        for (int i = 0; i < CHAR_SIZE; i++)
            this->character[i] = nullptr;
    }

    void insert(std::string);
    bool deletion(Trie*&, std::string);
    bool search(std::string);
    bool haveChildren(Trie const*);
};

In here does Trie*& and Trie** means Same?

Zig Razor
  • 3,381
  • 2
  • 15
  • 35

2 Answers2

1

No, they are not the same. Trie*& is a reference to a (Trie-)pointer, Trie** is a pointer to a (Trie-)pointer. To illustrate the difference, consider this:

void test_a(int*& refToPtr)
{
    refToPtr = new int();
    *refToPtr = 123;
}

To achieve the same using int**, your function would look like:

void test_b(int** ptrToPtr)
{
    *ptrToPtr = new int();
    **ptrToPtr = 123;
}

One difference to keep in mind is that you can locally change ptrToPtr (so you can change to which pointer variable ptrToPtr points). With refToPtr being a reference, it is impossible to locally change to which pointer variable refToPtr refers.

0

No, they are not the same.

In here does Trie*& and Trie** means Same?

  • Trie*&: is a reference to pointer.
  • Trie**: is pointer to pointer.

For more information, you can take a look at

Dharman
  • 30,962
  • 25
  • 85
  • 135
ibra
  • 1,164
  • 1
  • 11
  • 26