Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code explanation plz (newb)??? 1

Status
Not open for further replies.

JANET1979

Vendor
Dec 3, 2002
13
GB
class Library
{
private:

Book the collection[20];
int noofbooks;

public:
Library ();
~Library ();
void borrowBook(User aUser);
};


ok firstly there is a another two classes called 'User' and 'Book' and a object called
aUser which has been created.

my question is how come in the private data part
'Book the collection[20];' works; can 'Book' (a class) be a variable type ???

Also the 'void borrowBook(User aUser)' part; again is this an example of the class 'User' being written like a variable type, for instance (int intname) ???

Hope this is clear enough, thanks.
 
A class can use used as a variable type because a class is a variable type. That's the whole reason you define a class in the first place: to create a new type. The code for a class X is (generally speaking) a description of objects (variables) of type X.
 
Code:
void borrowBook(User aUser);
is a method-declaration (in a .h - file).

In the 'library.cc' or .cpp or ... - class-definition you should find something like

Code:
void Library::borrowBook(User aUser)
{
// details
}

A User isn't create in that code, but it is enforced, that somebody, using a Library object, may call this method with a User - parameter.
Code:
User bjarne = new User ("Bjarne", "Strustroup", ...);
Library agb = new Library ();
agb.borrowBook (bjarne);
// but where is the book to borrow?

I'm confused about following:
Code:
Book the collection[20];
If it is
Code:
Book the_collection[20];
I could sleep well - but the statement in this form disquiets me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top