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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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