0

Reading a code base and desperately trying to understand it.

template<typename selection>
void run_z_p_selection(xml_config &my_config){
system::start();
std::shared_ptr<selection> my = std::make_shared<selection>(my_config, machine, enable, timet);
system::addSelection(my);
 }
  1. (xml_config &my config){}. Is this an object being created as an address? I don't understand.
  2. Where are all the (my_config, machine, enable, timet) coming from if they are not input arguments to the function?
  • The meaning of the `&` is overloaded. In this case, it means that `my_config` is a reference to an `xml_config` so it is [passing the argument by reference](http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/). The other variables have to be defined somewhere. – clcto Apr 14 '15 at 16:25
  • 1
    I feel like you've copied something wrong. `xml_config &my config` should by the arguments, buy there is a space in your variable name. I expect that should have been `xml_config &my_config` – Jonathan Mee Apr 14 '15 at 16:27
  • 1
    @Jonathan Mee Thank you. Corrected. – A.L. Verminburger Apr 14 '15 at 16:29

2 Answers2

0
  1. That is something called pass by reference

  2. It's hard to tell without seeing the whole code base, but it looks like those are global variables. Maybe system::start() sets them up?

Omada
  • 784
  • 4
  • 11
  • Not in system::start(). I have multiple code segments like that. All identical, but the argument names in (...) varying. I have been told that all those function templates could be reduced to one variadic template, but don't know how as machine, enable are not the actual input arguments to the function. – A.L. Verminburger Apr 14 '15 at 16:45
0
  1. xml_config &my_config is a reference: http://en.cppreference.com/w/cpp/language/reference A reference is an:

Alias to an already-existing object or function

  1. my_config is the argument passed in that is an xml_config&. machine, enable, and timet are all variables which are in scope for your function. And that could mean a lot of things.

    • If run_z_p_selection is a method, these could be member variables.
    • Because run_z_p_selection is a template I assume that it is defined in your header, so you shouldn't need to look in included source files for these, only in included headers.
    • The variables must either be defined in run_z_p_selection's namespace, a containing namespace, or the global namespace.

If you have Visual Studio you can select the variable you want to know about and press: Ctrl + F12 to jump to where it is defined in your project.

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288