help with constructor

D

Daniel

What does the line do after the last colon below?

// faststring.h
class FastString {
char *m_psz
public:
FastString(const char *psz);

// faststring.cpp
FastString::FastString(const char *psz)
: m_psz(new char[strlen(psz) + 1])
{
}
 
B

Brian Muth

It is calling the constructor for the m_psz member variable, and passing a pointer to some allocated memory as a value.

Note I can do this for other built-in variable types as well:

int i1= 5;
int i2 = int (5);
int i3 (5);

all do pretty much the same thing, in terms of declaring and assigning a value to a variable.
 
D

Daniel

What if I want to call a constructor for another member variable, would I
separate it from the other constructor with a comma or another colon?

--

Daniel



Brian Muth said:
It is calling the constructor for the m_psz member variable, and passing a
pointer to some allocated memory as a value.

Note I can do this for other built-in variable types as well:

int i1= 5;
int i2 = int (5);
int i3 (5);

all do pretty much the same thing, in terms of declaring and assigning a
value to a variable.




Daniel said:
What does the line do after the last colon below?

// faststring.h
class FastString {
char *m_psz
public:
FastString(const char *psz);

// faststring.cpp
FastString::FastString(const char *psz)
: m_psz(new char[strlen(psz) + 1]) {
}
 

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

Top