RE: Error on Member Initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eljay,

While that's the _preferred_ way to initialize member variables in C++, that's not always possible; sometimes you need to do more complex things to initialize your class (e.g., if you need to initialize variables differently based on certain conditions, retrieve information from a database, etc.).  Is there any _real_ difference between these two ways of initializing?

radApp::radApp()
: m_MyServer(&Log)
{}


radApp ::radApp()
{
  m_MyServer = &Log ;
}

Thanks,
Lyle Taylor
IS Applications

-----Original Message-----
From: Eljay Love-Jensen [mailto:eljay@xxxxxxxxx]
Sent: Saturday, September 13, 2003 8:28 AM
To: Allen Williams; gcc-help@xxxxxxxxxxx
Subject: Re: Error on Member Initialization

Hi Allen,

That's not how you initialize a member variable in C++.  (Although it's very close to how you do it in Java.)

You need to put the initialization in your radApp's constructor's initialization list.

e.g.:
radApp::radApp()
: m_MyServer(&Log)
{ }

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux