0
0
0nk0l0g2015-11-22 18:19:05
OOP
0nk0l0g, 2015-11-22 18:19:05

How to initialize a static field?

Good afternoon.
There is a class agents, it has a static field
static graph general_graph;
Where graph is another class. This class has a fill() method - it reads a graph from a file.
Problem: I can't initialize a static variable with a graph object with the fill() method already executed without creating a global object.
outside the main function I write the following code:
graph agents::general_graph = *(new graph());
the code compiles without error, but how do you call the fill() method on initialization?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Tsilyurik, 2015-11-22
@0nk0l0g

This class has a fill() method - it reads a graph from a file.

After all, your method is called somehow like this: ?.fill(<file_name>)?
A good option is to have an overloaded graph(<filename>) constructor that does the same as fill().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question