S
S
SaveliTomak2016-04-08 21:03:18
C++ / C#
SaveliTomak, 2016-04-08 21:03:18

How to assign an object of another class to a field in a class constructor?

Hello everyone, how to assign an object of another class to a field in a class constructor, I do this:

class Stack
{
private:
    DynamicArray *arr;
public:
    Stack() {
        this->arr = new DynamicArray();
    }
}

There is no syntax error, the methods of the DynamicArray class in the IDE are autocompleted, called without an error, but do not work.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JonNiBravo, 2016-04-09
@JonNiBravo

In general, the code is correct, what exactly does not work?
can it be like this

class Stack
{
private:
    DynamicArray *arr;
public:
    Stack()  : arr(new DynamicArray())
    {
        assert(arr);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question