Question about C++ syntax - Newbie requesting help

A

angusyoung1000

Well, I'm new to C++ and seem to get tangled up the C++ syntax quite
often. Here is my latest dilemma. Let's say I have something like:

String::String(const char *s) : length(strlen(s))

What is happening when the last : is encountered?

: length(strlen(s))

Sorry, I can't seem to find any explanation of this in my C++ book.

Your help will be appreciated.

Thx.
 
A

Artie Gold

angusyoung1000 said:
Well, I'm new to C++ and seem to get tangled up the C++ syntax quite
often. Here is my latest dilemma. Let's say I have something like:

String::String(const char *s) : length(strlen(s))

What is happening when the last : is encountered?

: length(strlen(s))

Sorry, I can't seem to find any explanation of this in my C++ book.

Your help will be appreciated.

Thx.

It's an *initialization list*. Look that up in the index.

HTH,
--ag
 
S

Sharad Kala

angusyoung1000 said:
Sorry, I can't seem to find any explanation of this in my C++ book.

Which book are you reading ? You should consider changing your book if it
doesn't even talk about initialization lists. Check reviews of books at
http://www.accu.org.

Sharad
 
S

Stuart Gerchick

This is an initilization list. anything after the : will be set
before th main body of the program. So, length will get initalized.

Pls try to find a complete book. Lippman's C++ primer is a good, if
think source
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top