204x Filetype PDF File size 0.37 MB Source: www.ge.infn.it
(Minimal) (Minimal) (Practical) (Practical) Introduction to C++ and OOP Introduction to C++ and OOP For use in the Geant4 course Largely incomplete Not meant to replace good C++, UML, and OOP books! Maria Grazia Pia C++ basics C++ basics C++ is not an object oriented language A “superset” of C You can write procedural code in C++ Maria Grazia Pia // my first program in C++ Getting started #includeGetting started intmain () { std::cout << "Hello World!"; return 0; } // This is a comment line comment cout << "Hello World"; C++ statement #include cout is declared in the iostream directive for the preprocessor preprocessor standard file within the std namespace int main () cin beginning of the definition of semicolon (;) marks the end of the the statement main function main function the main function is the point return 0; by where all C++ programs the return statement causes the main start their execution function to finish all C++ programs must have return may be followed by a return a main function code (here: 0) body enclosed in braces {} ¾return code 0 for the main function is generally Maria Grazia Pia interpreted as the program worked OK Compilation Compilation make myFirstProgram Preprocessor Compiler Inlines #includes etc. Translates into machine code Associates calls with functions Object files Executable Linker myFirstProgram Associates functions with definitions External Libraries, libc.so, libcs123.so Maria Grazia Pia