http://www.parashift.com/c++-faq-lite/calling-virtuals-from-ctors.html

 

#include <iostream>
#include <string>

void println(std::string const& msg)
{ std::cout << msg << '\n'; }

class Base {
public:
  Base()              { println("Base::Base()");  virt(); }
  virtual void virt() { println("Base::virt()"); }
};

class Derived : public Base {
public:
  Derived()           { println("Derived::Derived()");  virt(); }
  virtual void virt() { println("Derived::virt()"); }
};

int main()
{
  Derived d;
}

創作者介紹
創作者 hedgezzz 的頭像
hedgezzz

hedgezzz的部落格

hedgezzz 發表在 痞客邦 留言(0) 人氣()