2.3 Create the main function

(Linux version)

< 2.2 | 2.3 | 2.4 >

Every C++ program must define an entry point in the form of a main function .

Edit the file main.cpp in the src directory and replace the text that is there with the following:

#include &lt;iostream&gt;	
#include "node.hpp"
#include "tree.hpp"

using namespace strom;

const double Node::_smallest_edge_length = 1.0e-12;

int main(int argc, const char * argv[]) {
    std::cout &lt;&lt; "Starting..." &lt;&lt; std::endl;
    Tree tree;
    std::cout &lt;&lt; "\nFinished!" &lt;&lt; std::endl;

    return 0;
}	

Explanation of main.cpp

Recall that the data member _smallest_edge_length in the class Node was declared to be static, so we must initialize it in a source code file, and main.cpp is our only source code file, hence the line that sets _smallest_edge_length to the very tiny value 1.0e-12.

The main function firsts announces that the program is starting to run (by displaying Starting... to standard output), then creates a Tree object having nodes made of Node objects, then announces that the program is finished running just before returning 0 (the exit code 0 tells the operating system that the program ended normally).

< 2.2 | 2.3 | 2.4 >