A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FClass%2FDestructor</id>
		<title>C++/Class/Destructor - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FClass%2FDestructor"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Class/Destructor&amp;action=history"/>
		<updated>2026-04-10T05:15:38Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Class/Destructor&amp;diff=1348&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Class/Destructor&amp;diff=1348&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Class/Destructor&amp;diff=1349&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Class/Destructor&amp;diff=1349&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:39Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Constructing and Destructing sequence for two base classes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class BaseClass1 {&lt;br /&gt;
public:&lt;br /&gt;
  BaseClass1() { cout &amp;lt;&amp;lt; &amp;quot;Constructing BaseClass1\n&amp;quot;; }&lt;br /&gt;
  ~BaseClass1() { cout &amp;lt;&amp;lt; &amp;quot;Destructing BaseClass1\n&amp;quot;; }&lt;br /&gt;
};&lt;br /&gt;
class BaseClass2 {&lt;br /&gt;
public:&lt;br /&gt;
  BaseClass2() { cout &amp;lt;&amp;lt; &amp;quot;Constructing BaseClass2\n&amp;quot;; }&lt;br /&gt;
  ~BaseClass2() { cout &amp;lt;&amp;lt; &amp;quot;Destructing BaseClass2\n&amp;quot;; }&lt;br /&gt;
};&lt;br /&gt;
class DerivedClass: public BaseClass1, public BaseClass2 {&lt;br /&gt;
public:&lt;br /&gt;
  DerivedClass() { cout &amp;lt;&amp;lt; &amp;quot;Constructing DerivedClass\n&amp;quot;; }&lt;br /&gt;
  ~DerivedClass() { cout &amp;lt;&amp;lt; &amp;quot;Destructing DerivedClass\n&amp;quot;; }&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  DerivedClass ob;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Define and use the destructor==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class myclass {&lt;br /&gt;
  int a;&lt;br /&gt;
public:&lt;br /&gt;
  myclass();                   // constructor&lt;br /&gt;
  ~myclass();                  // destructor&lt;br /&gt;
  void show();&lt;br /&gt;
};&lt;br /&gt;
myclass::myclass()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;In constructor\n&amp;quot;;&lt;br /&gt;
  a = 10;&lt;br /&gt;
}&lt;br /&gt;
myclass::~myclass()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Destructing...\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void myclass::show()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  myclass ob;&lt;br /&gt;
  ob.show();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Define destrcuctor outside the class definition==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class Book &lt;br /&gt;
{&lt;br /&gt;
  public: &lt;br /&gt;
    char title[256];&lt;br /&gt;
    char author[64];&lt;br /&gt;
    float price;&lt;br /&gt;
    Book(char *title, char *author, char *publisher, float price);&lt;br /&gt;
    ~Book(void);&lt;br /&gt;
    void show_title(void) { cout &amp;lt;&amp;lt; title &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; };&lt;br /&gt;
    float get_price(void) { return(price); };&lt;br /&gt;
    void show_book(void) &lt;br /&gt;
    { &lt;br /&gt;
      show_title(); &lt;br /&gt;
      show_publisher();&lt;br /&gt;
    };&lt;br /&gt;
    void assign_publisher(char *name) { strcpy(publisher, name); };&lt;br /&gt;
  private:&lt;br /&gt;
    char publisher[256];&lt;br /&gt;
    void show_publisher(void) { cout &amp;lt;&amp;lt; publisher &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; };&lt;br /&gt;
};&lt;br /&gt;
Book::Book(char *title, char *author, char *publisher, float price)&lt;br /&gt;
 {&lt;br /&gt;
   strcpy(Book::title, title);&lt;br /&gt;
   strcpy(Book::author, author);&lt;br /&gt;
   strcpy(Book::publisher, publisher);&lt;br /&gt;
   Book::price = price;&lt;br /&gt;
 }&lt;br /&gt;
Book::~Book(void)&lt;br /&gt;
 {&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Destructing the instance &amp;quot; &amp;lt;&amp;lt; title &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
int main(void)&lt;br /&gt;
 {&lt;br /&gt;
   Book tips(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, 49.95);&lt;br /&gt;
   Book diary(&amp;quot;D&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, 9.95);&lt;br /&gt;
   tips.show_book();&lt;br /&gt;
   diary.show_book();&lt;br /&gt;
 }&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Derived class call its base constructor==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class BaseClass {&lt;br /&gt;
protected:&lt;br /&gt;
  int i;&lt;br /&gt;
public:&lt;br /&gt;
  BaseClass(int x) { &lt;br /&gt;
     i = x; &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Constructing base\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  ~BaseClass() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Destructing base\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
class DerivedClass: public BaseClass {&lt;br /&gt;
  int j;&lt;br /&gt;
public:&lt;br /&gt;
  DerivedClass(int x, int y): BaseClass(y) { &lt;br /&gt;
     j = x; &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Constructing DerivedClass\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  ~DerivedClass() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Destructing DerivedClass\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  void show() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; j &amp;lt;&amp;lt; endl; &lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  DerivedClass ob(3, 4);&lt;br /&gt;
  ob.show();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Derived constructor uses no parameters==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class BaseClass1 {&lt;br /&gt;
protected:&lt;br /&gt;
  int i;&lt;br /&gt;
public:&lt;br /&gt;
  BaseClass1(int x) { &lt;br /&gt;
     i =x; &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Constructing BaseClass1\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  ~BaseClass1() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Destructing BaseClass1\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
class BaseClass2 {&lt;br /&gt;
protected:&lt;br /&gt;
  int k;&lt;br /&gt;
public:&lt;br /&gt;
  BaseClass2(int x) { &lt;br /&gt;
     k = x; &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Constructing base2\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  ~BaseClass2() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Destructing base2\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
class DerivedClass: public BaseClass1, public BaseClass2 {&lt;br /&gt;
public:&lt;br /&gt;
  DerivedClass(int x, int y): BaseClass1(x), BaseClass2(y) { &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Constructing DerivedClass\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  ~DerivedClass() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;Destructing DerivedClass\n&amp;quot;; &lt;br /&gt;
  }&lt;br /&gt;
  void show() { &lt;br /&gt;
     cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; k &amp;lt;&amp;lt; endl; &lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  DerivedClass ob(3, 4);&lt;br /&gt;
  ob.show();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implement a destructor==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class prompt {&lt;br /&gt;
  int count;&lt;br /&gt;
public:&lt;br /&gt;
  prompt(char *s) { &lt;br /&gt;
     cout &amp;lt;&amp;lt; s; cin &amp;gt;&amp;gt; count; &lt;br /&gt;
  };&lt;br /&gt;
  ~prompt();&lt;br /&gt;
};&lt;br /&gt;
prompt::~prompt() {&lt;br /&gt;
  int i, j;&lt;br /&gt;
     &lt;br /&gt;
  for(i = 0; i &amp;lt;count; i++) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;\a&amp;quot;;&lt;br /&gt;
    for(j=0; j&amp;lt;32000; j++) &lt;br /&gt;
       ; // delay&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  prompt ob(&amp;quot;Enter a number: &amp;quot;);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==System will call the destructor==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class myclass {&lt;br /&gt;
public:&lt;br /&gt;
  int who;&lt;br /&gt;
  myclass(int id);&lt;br /&gt;
  ~myclass();&lt;br /&gt;
};&lt;br /&gt;
myclass::myclass(int id)&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Initializing &amp;quot; &amp;lt;&amp;lt; id &amp;lt;&amp;lt; endl;&lt;br /&gt;
  who = id;&lt;br /&gt;
}&lt;br /&gt;
myclass::~myclass()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Destructing &amp;quot; &amp;lt;&amp;lt; who &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  myclass object1(3);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Here.\n&amp;quot;;&lt;br /&gt;
  myclass object2(4);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using a constructor and destructor.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
#define SIZE 10&lt;br /&gt;
class stack {&lt;br /&gt;
  int stck[SIZE];&lt;br /&gt;
  int topOfStack;&lt;br /&gt;
public:&lt;br /&gt;
  stack();  // constructor&lt;br /&gt;
  ~stack(); // destructor&lt;br /&gt;
  void push(int i);&lt;br /&gt;
  int pop();&lt;br /&gt;
};&lt;br /&gt;
// constructor&lt;br /&gt;
stack::stack(){&lt;br /&gt;
  topOfStack = 0;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Stack Initialized\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
// destructor&lt;br /&gt;
stack::~stack(){&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Stack Destroyed\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void stack::push(int i){&lt;br /&gt;
  if( topOfStack == SIZE ) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Stack is full.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  stck[ topOfStack ] = i;&lt;br /&gt;
  topOfStack++;&lt;br /&gt;
}&lt;br /&gt;
int stack::pop() {&lt;br /&gt;
  if( topOfStack == 0 ) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Stack underflow.\n&amp;quot;;&lt;br /&gt;
    return 0;&lt;br /&gt;
  }&lt;br /&gt;
  topOfStack--;&lt;br /&gt;
  return stck[ topOfStack ];&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  stack a, b;&lt;br /&gt;
  &lt;br /&gt;
  a.push(1);&lt;br /&gt;
  b.push(2);&lt;br /&gt;
  a.push(3);&lt;br /&gt;
  b.push(4);&lt;br /&gt;
  cout &amp;lt;&amp;lt; a.pop() &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; a.pop() &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; b.pop() &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; b.pop() &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>