I come from a C# background. I'm trying to interpret the following C++ code:
/* A typical Library with a collection of books.
* This library will publish an event to all members whenever a new book is arrived
vector<Book> bookList; //Collection of books.
newBookEvent(this) //Set the source of event as the current object
GoFPatterns::Event<Library, Book&> newBookEvent; //Declaring an event
//which will be fired when a
//new book is added to library
* Library public constructor which initializes library name and the Event
Library(string name) :
libraryName(name), newBookEvent(this) //Set the source of event will
//be the current object
* Function to add a new book to library
void AddBook(Book newBook)
//Add the book to collection
//Fire the newBookEvent with the newly added book as argument
We are defining a class named Library
It has a private array of Book
s (the vector) named bookList
Then there's a private constructor? named Library()
which has no arguments. After that is a colon : , and what is newBookEvent(this)
? I'm not sure what this colon notation means.
There's a public string libraryName
a public variable newBookEvent
which holds an instance of class Event
from namespace GoFPatterns
A public constructor Library
with one string parameter (name), again a colon and libraryName(name) comma, newBookEvent(this). That's where I get lost.
Finally a void function AddBook
which takes one parameter of type Book
class, which has 2 lines of executable code.