Answer the question
In order to leave comments, you need to log in
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();
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question