class Thread {
private:
int running;
unsigned long m_pid;
protected:
Thread();
};
///this is the strange part.
Thread::Thread()
: running(0)
, m_pid(0L)
{
}
Thread::Thread()
{
running = 0;
m_pid = 0L;
}
class Thread {
private:
int running;
unsigned long m_pid;
protected:
Thread();
};
///this is the strange part.
Thread::Thread()
: running(0)
, m_pid(0L)
{
}
Thread::Thread()
{
running = 0;
m_pid = 0L;
}
Quote:Original post by Sharlin
Also, initializer lists are the only way to call a base class's constructor from a derived constructor.
DerivedConstructor::DerivedConstructor() { BaseConstructor::BaseConstructor(); //call it from here.}
Quote:Original post by johnnyBravo
I don't understand, can't you do:
*** Source Snippet Removed ***
Quote:Original post by johnnyBravoQuote:Original post by Sharlin
Also, initializer lists are the only way to call a base class's constructor from a derived constructor.
I don't understand, can't you do:
*** Source Snippet Removed ***
Quote:Original post by Shannon BarberQuote:Original post by johnnyBravoQuote:Original post by Sharlin
Also, initializer lists are the only way to call a base class's constructor from a derived constructor.
I don't understand, can't you do:
*** Source Snippet Removed ***
Nope, won't compile.
class Base {public: Base(){}};class Derived:public Base {public: Derived(){Base::Base();}};
Quote:Original post by silencer-Quote:Original post by johnnyBravo
I don't understand, can't you do:
*** Source Snippet Removed ***
That will call the base ctor twice.
Quote:Original post by Sharlin
Also, initializer lists are the only way to call a base class's constructor from a derived constructor.
Quote:Original post by johnnyBravo
So what does this mean?, like in what situation would this be useful?
Thanks.
class Base{public: Base(int num) { /* Do whatever */ } // This should only be called once.};class Derived : public Base{public: Derived(int num) : Base(num) { } // Calls base ctor with int value.};