Jump to content
СофтФорум - всё о компьютерах и не только

конструкторы/деструкторы с++

Recommended Posts

всем привет, помогите разобраться с деструктор, почему при его вызове не появляется сообщение, что он вызван, или может быть он совсем не вызывается. заранее спасибо

заголовочный файл:

#include <string>class Account{  private:		  std::string fullname;		  std::string number;		  double balance;  public:		 Account();		 Account(const char* client, const char* num, double total = 0.0);		 ~Account();		 void show();		 void deposit(double cash);		 void withdraw(double cash);};

код функции членов:

#include <iostream>#include <string>#include "account.h"Account::Account(){			  std::cout << "default constructor\n";			  fullname = "unknown";			  number = "XXXXXXXX";			  balance = 0.0;}Account::Account(const char* client, const char* num, double total){				   std::cout << "constructor for " << client << "\n";				   fullname = client;				   number = num;				   balance = total;}Account::~Account(){			   std::cout << "destructor for " << fullname << "\n";}void Account::deposit(double cash){ balance += cash;}void Account::withdraw(double cash){ if (balance <= 0)	std::cout << "you can't withdraw money, you balance is negative\n"; else balance -= cash;}void Account::show(){		   using std::cout;		   using std::endl;		   cout << "Client's name: " << fullname << endl				<< "Client's number: " << number << endl				<< "Balance: " << balance << endl;}

код функции main():

#include <iostream>#include "account.h"int main(){using std::cout;using std::ios_base;cout.precision(2);cout.setf(ios_base::fixed, ios_base::floatfield);cout.setf(ios_base::showpoint);cout << "using constructor for creating new object:\n";Account person("some body", "46271003", 100000.0);person.show();person.deposit(5000.0);person.show();person.withdraw(9000.0);person.show();system("PAUSE");return 0;}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...