faq6 - ). You can actually have multiple different...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
FREQUENTLY ASKED QUESTIONS October 19, 2011 Content Questions What is a constructor and how do you use it? A “constructor” is code that gets executed when an object gets instantiated (created in memory). The constructor code is part of the class definition. The “default constructor” is called whenever the object is instantiated: this is a simple one, for class Animal . Animal::Animal () { } or the constructor could set the data member values that an instance of the class should have when it’s created: Animal::Animal () { size = 0.1; mass = 0.1; } You can define a constructor with arguments: Animal::Animal (float a, float b) { size = a; mass = b; } which would fill the Animal object at instantiation time with the values you specify (in a call like, e.g. Animal* elephant = new Animal(10.,100.);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ). You can actually have multiple different constructors defined (which is called “overloading”) and the compiler will figure out which one to call based on the number and ordering of the data types of the arguments. So you could have both of the above two constructors defined, and create objects in your code according to either Animal* elephant = new Animal(10.,100.); or Animal* mouse = new Animal(); What is a G4 event? Is it each time a primary is generated or each time a particle enters a detector? It’s each time a primary is generated (although note that more than one particle can be generated at the same time; if multiple particles are generated by the primary generator, there will be more than one particle tracked in the event.)...
View Full Document

This note was uploaded on 01/16/2012 for the course PHYSICS 392 taught by Professor Scholberg during the Fall '11 term at Duke.

Page1 / 2

faq6 - ). You can actually have multiple different...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online