shared pointer

I have a class as follows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Node:protected Model
{
public:


	int sizeofneighbour;
	VecDbl_t distributions_;
	VecDbl_t newDistributions_;
	std::shared_ptr<Node> neighbours_[9];

	VecInt_t* position;

	static const double PI;
public:
	Node(VecInt_t *pos);
	~Node();
};


I have a shared pointer neighbours_ with size of 9. I want to define this share pointer with a size which is calculated during run time. I know it should be something like
1
2
3
std::shared_ptr<Node> neighbours_ = std::shared_ptr<Node>(new Node(position));
	for (auto i = 0; i < size; i++) {
		Node(position).push_back(neighbours_);

}
but I don't know why I can't do the push back. Thanks for your helps in advance.
Last edited on
I have a shared pointer neighbours_ with size of 9.

You have an array of 9 shared pointers.

If you want a resizeable array you can use std::vector.

 
std::vector<std::shared_ptr<Node>> neighbours_;

 
neighbours_.push_back(std::make_shared<Node>(position));
Last edited on
@Peter87 Thanks for your answer.
Topic archived. No new replies allowed.