help with constructor

  • Thread starter Thread starter Daniel
  • Start date Start date
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])
{
}
 
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.
 
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]) {
}
 
Back
Top