How to declare a file as a variable in other class

Hello i want to declare a new file for each class as a variable.
eg.
1
2
3
4
5
6
7
8
9
10
11
class bst
{
	node *root;
        ofstream out("out.txt"); //i want to do someting like this
	public:
	int num_elem;
	bst(){root=NULL; num_elem=0;}
	void insert(int value);
	void inorder();
	void print_inorder(node *curr,int i);
};


Any help?
1
2
3
4
5
6
class bst{
public:
   bst(const char *filename): out(filename){/**/}
private:
   std::ofstream out;
};

If you want it self incrementing then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class bst{
private:
   static int number_of_instances;
   bst():
      out(
         std::string("out_")
         + to_string(number_of_instances)
         + ".txt"
      )
   {
      ++number_of_instances;
      ///...
   }
};

int bst::number_of_instances = 0;
Thanks ne555.
And much thanks for increament section.
Worked!
Topic archived. No new replies allowed.