"No Appropriate Default Constructor Available"

Pages: 12
I have been working on this program for two days now and I can see the light at the end of the tunnel, but I am stuck. I posted on here earlier with an a completely separate issue and everyone who helped out was great! I just do not understand though why I am having trouble with this account class though.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//banking system driver program

#include "BankingSystem.h" // Account class definition
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib> // exit function prototype
using namespace std;



int enterChoice();
void createTextFile( fstream& );
void updateRecord( fstream& );
void newRecord( fstream& );
void deleteRecord( fstream& );
void outputLine( ostream&, const Account & );
int getAccount( const char * const );

enum Choices { PRINT = 1, UPDATE, NEW, DELETE, END };
int main()
{

   // open file for reading and writing
   fstream inOutCredit( "credit.dat", ios::in | ios::out | ios::binary );

   // exit program if fstream cannot open file
   if ( !inOutCredit ) 
   {
      cerr << "File could not be opened." << endl;
      exit ( 1 );
   } // end if
   
   int choice; // store user choice

   // enable user to specify action
   while ( ( choice = enterChoice() ) != END ) 
   {
      switch ( choice ) 
      {
         case PRINT: // create text file from record file
            createTextFile( inOutCredit );
            break;
         case UPDATE: // update record
            updateRecord( inOutCredit );
            break;
         case NEW: // create record
            newRecord( inOutCredit );
            break;
         case DELETE: // delete existing record
            deleteRecord( inOutCredit );
            break;
         default: // display error if user does not select valid choice
            cerr << "Incorrect choice" << endl;
            break;
      } // end switch

      inOutCredit.clear(); // reset end-of-file indicator
   } // end while
} // end main

// enable user to input menu choice
int enterChoice()
{
   // display available options
	std::cout << "\nEnter your choice" << endl
      << "1 - store a formatted text file of accounts" << endl
      << "2 - called \"print.txt\" for printing" << endl
      << "3 - update an account" << endl
      << "4 - add a new account" << endl
      << "5 - delete an account" << endl
      << "6 - end program\n? ";

   int menuChoice;
   std::cin >> menuChoice; // input menu selection from user
   return menuChoice;
} // end function enterChoice

// create formatted text file for printing
void createTextFile( fstream &readFromFile )
{
   // create text file
   ofstream outPrintFile( "print.txt", ios::out );

   // exit program if ofstream cannot create file
   if ( !outPrintFile ) 
   {
      cerr << "File could not be created." << endl;
      exit( 1 );
   } // end if

   outPrintFile << left << setw( 10 ) << "Account" << setw( 16 )
      << "Last Name" << setw( 11 ) << "First Name" << right
      << setw( 10 ) << "Balance" << endl;

   // set file-position pointer to beginning of readFromFile
   readFromFile.seekg( 0 );

   // read first record from record file
   Account client;
   readFromFile.read( reinterpret_cast< char * >( &client ),
      sizeof( Account ) );

   // copy all records from record file into text file
   while ( !readFromFile.eof() ) 
   {
      // write single record to text file
      if ( client.getAccountNumber() != 0 ) // skip empty records
         outputLine( outPrintFile, client );

      // read next record from record file
      readFromFile.read( reinterpret_cast< char * >( &client ), 
         sizeof( Account ) );
   } // end while
} // end function createTextFile

// update balance in record
void updateRecord( fstream &updateFile )
{
   // obtain number of account to update
   int accountNumber = getAccount( "Enter account to update" );

   // move file-position pointer to correct record in file
   updateFile.seekg( ( accountNumber - 1 ) * sizeof( Account ) );

   // read first record from file
   Account client;
   updateFile.read( reinterpret_cast< char * >( &client ), 
      sizeof( Account ) );

   // update record
   if ( client.getAccountNumber() != 0 ) 
   {
      outputLine( cout, client ); // display the record

      // request user to specify transaction
	  std::cout << "\nEnter charge (+) or payment (-): ";
      double transaction; // charge or payment
	  std::cin >> transaction;

      // update record balance
      double oldBalance = client.getBalance();
      client.setBalance( oldBalance + transaction );
      outputLine( cout, client ); // display the record

      // move file-position pointer to correct record in file
      updateFile.seekp( ( accountNumber - 1 ) * sizeof( Account ) );

      // write updated record over old record in file
      updateFile.write( reinterpret_cast< const char * >( &client ), 
         sizeof( Account ) );
   } // end if
   else // display error if account does not exist
      cerr << "Account #" << accountNumber 
         << " has no information." << endl;
} // end function updateRecord

// create and insert record
void newRecord( fstream &insertInFile )
{
   // obtain number of account to create
   int accountNumber = getAccount( "Enter new account number" );

   // move file-position pointer to correct record in file
   insertInFile.seekg( ( accountNumber - 1 ) * sizeof( Account ) );

   // read record from file
   Account client;
   insertInFile.read( reinterpret_cast< char * >( &client ), 
      sizeof( Account ) );

   // create record, if record does not previously exist
   if ( client.getAccountNumber() == 0 ) 
   {
      string lastName;
      string firstName;
      double balance;

      // user enters last name, first name and balance
	  std:: cout << "Enter lastname, firstname, balance\n? ";
	  std::cin >> lastName;
	  std::cin >> firstName;
	  std::cin >> balance;

      // use values to populate account values
      client.setLastName( lastName );
      client.setFirstName( firstName );
      client.setBalance( balance );
      client.setAccountNumber( accountNumber );

      // move file-position pointer to correct record in file
      insertInFile.seekp( ( accountNumber - 1 ) * sizeof( Account ) );

      // insert record in file                       
      insertInFile.write( reinterpret_cast< const char * >( &client ),
         sizeof( Account ) );                     
   } // end if
   else // display error if account already exists
      cerr << "Account #" << accountNumber
         << " already contains information." << endl;
} // end function newRecord

// delete an existing record
void deleteRecord( fstream &deleteFromFile )
{
   // obtain number of account to delete
   int accountNumber = getAccount( "Enter account to delete" );

   // move file-position pointer to correct record in file
   deleteFromFile.seekg( ( accountNumber - 1 ) * sizeof( Account ) );

   // read record from file
   Account client;
   deleteFromFile.read( reinterpret_cast< char * >( &client ), 
      sizeof( Account ) );

   // delete record, if record exists in file
   if ( client.getAccountNumber() != 0 ) 
   {
      Account blankClient; // create blank record

      // move file-position pointer to correct record in file
      deleteFromFile.seekp( ( accountNumber - 1 ) * 
         sizeof( Account ) );

      // replace existing record with blank record
      deleteFromFile.write( 
         reinterpret_cast< const char * >( &blankClient ), 
         sizeof( Account ) );

	  std::cout << "Account #" << accountNumber << " deleted.\n";
   } // end if
   else // display error if record does not exist
      cerr << "Account #" << accountNumber << " is empty.\n";
} // end deleteRecord

// display single record
void outputLine( ostream &output, const Account &record )
{
   output << left << setw( 10 ) << record.getAccountNumber()
      << setw( 16 ) << record.getLastName()
      << setw( 11 ) << record.getFirstName()
      << setw( 10 ) << setprecision( 2 ) << right << fixed 
      << showpoint << record.getBalance() << endl;
} // end function outputLine

// obtain account-number value from user
int getAccount( const char * const prompt )
{
   int accountNumber;

   // obtain account-number value
   do 
   {
	   std::cout << prompt << " (1 - 100): ";
	   std::cin >> accountNumber;
   } while ( accountNumber < 1 || accountNumber > 100 );

   return accountNumber;
} // end function getAccount 
From what the errors are telling me, it seems as if there is something wrong with my account class. But, I cannot figure out what. I have tried changing variables and functions, but I do not understand why there is no appropriate default constructor.


1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(100) : error C2512: 'Account' : no appropriate default constructor available
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(127) : error C2512: 'Account' : no appropriate default constructor available
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(168) : error C2512: 'Account' : no appropriate default constructor available
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(213) : error C2512: 'Account' : no appropriate default constructor available
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(220) : error C2512: 'Account' : no appropriate default constructor available
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(240) : error C2662: 'Account::getAccountNumber' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(241) : error C2662: 'Account::getLastName' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(242) : error C2662: 'Account::getFirstName' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingdriver.cpp(244) : error C2662: 'Account::getBalance' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers
1>BankingSystem.cpp
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingsystem.cpp(19) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingsystem.cpp(49) : error C2511: 'int Account::getPassCode(void) const' : overloaded member function not found in 'Account'
1> c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingsystem.h(9) : see declaration of 'Account'
1>c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingsystem.cpp(71) : error C2511: 'double Account::getBalance(void) const' : overloaded member function not found in 'Account'
1> c:\users\jmh10_000\documents\visual studio 2008\projects\project 2\bankingsystem.h(9) : see declaration of 'Account'



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef BANKING_SYSTEM_H
#define BANKING_SYSTEM_H

#include <string> // Used to allow string functions
#include <vector>
#include <iostream> 


class Account {

public:
  Account( int accountNumberValue, int passCode, std::string lastName, 
           std::string firstName, double balance);
  ~Account();

  void setFirstName ( std::string & );
  std::string getFirstName();

  void setLastName( std::string & );
  std::string getLastName();

  void setAccountNumber( int accountNumberValue );
  int getAccountNumber();

  void setPassCode( int passCodeValue );
  int getPassCode();

  void setBalance( double balanceValue );
  double getBalance();


private:
  std::string firstName;
  std::string lastName;
  int accountNumber;
  int passCode;
  double balance;

}; // end class Account


class BankingSystem
{
public:
  BankingSystem();
  ~BankingSystem();

  Account query(int accountId);

  void addAccount();//option 1

  void deleteAccount();//option 2

  void AccountInquiry();//option 3

  void saveAccount();//option 4

  void loadAccounts();//option 5

private:
  std::vector<Account> accounts_;
};

#endif  


This above is my header file with my account class.
On line 100 you are default constructing an "Account" -- meaning that you are using a constructor that takes no arguments -- but your Account class does not provide such a constructor.

Duoas, thank you for taking the time for looking through this jumble. I really appreciate it.

I do not mean to sound stupid, but do I have to create a constructor?/ Can I just create it in my account class?

This is my first time working with a driver program and it has been nothing easy.
You can overload the ctor as much as you like. It's just a matter of having a default constructor declared in your class (and defined of course).

Account() {/*default values for accountID, password, first and last name and balance go here*/}
Thanking for your help xisinn.

Please correct me if I am wrong, but what you are saying I need a constructor for everything in the driver file in my class file?
Not exactly sure what you mean, probably because I'm silly.

What I meant was, that you simply add a default constructor to your Account class.
Here's your Account class with the your original constructor AND a default constructor:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Account {

public:
//here's your overloaded constructor
  Account( int accountNumberValue, int passCode, std::string lastName, 
           std::string firstName, double balance);
//and here's a default constructor.
  Account() {accountNumber=passcode=0; balance=0.0; firstName="John"; lastName="Doe";}
  ~Account();

  void setFirstName ( std::string & );
  std::string getFirstName();

  void setLastName( std::string & );
  std::string getLastName();

  void setAccountNumber( int accountNumberValue );
  int getAccountNumber();

  void setPassCode( int passCodeValue );
  int getPassCode();

  void setBalance( double balanceValue );
  double getBalance();


private:
  std::string firstName;
  std::string lastName;
  int accountNumber;
  int passCode;
  double balance;

};


The default constructor body(definition) doesn't necessarily need to be in your header file, I just put it there for demonstrative purposes.
Last edited on
Yes, that is exactly what I meant haha. I apologize for the confusion. And that got rid of all of the default constructor errors, but led to errors in my pointers. . I hate to bother you with another question, but does that mean I will have to change them to fit the default constructor?


Errors

2\bankingdriver.cpp(240) : error C2662: 'Account::getAccountNumber' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers

2\bankingdriver.cpp(241) : error C2662: 'Account::getLastName' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers

2\bankingdriver.cpp(242) : error C2662: 'Account::getFirstName' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers

2\bankingdriver.cpp(244) : error C2662: 'Account::getBalance' : cannot convert 'this' pointer from 'const Account' to 'Account &'
1> Conversion loses qualifiers
1>BankingSystem.cpp
I may have figured it out. I will update if it works.
Yeah, got it down to these last two errors. =D

2\bankingsystem.cpp(46) : error C2511: 'int Account::getPassCode(void) const' : overloaded member function not found in 'Account'

1> 2\bankingsystem.h(9) : see declaration of 'Account'

2\bankingsystem.cpp(68) : error C2511: 'double Account::getBalance(void) const' : overloaded member function not found in 'Account'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream> //
#include <string>

using namespace std;

#include "BankingSystem.h"

// constructor
Account::Account( int accountNumberValue, 
				 int passCodeValue,
				 string lastNameValue, 
				 string firstNameValue, 
				 double balanceValue
 )


{
 setAccountNumber( accountNumberValue );
   setPassCode ( passCodeValue );
   setLastName( lastNameValue );
   setFirstName( firstNameValue );
   setBalance( balanceValue );
}
// end constructor

// return first name
	string Account::getFirstName()
	{
		return firstName;

	}// getFirstName

// return last name
	string Account::getLastName()
	{
		return lastName;

	}// end getLastName


int Account::getAccountNumber() 
{
	return accountNumber;

}
int Account::getPassCode() const
{
	return passCode;
}


//set first name
void Account::setFirstName( string &first )
{
	firstName = first;

} // end function setFIrstName

//set last name

void Account::setLastName( string &last )
{
	lastName = last;

}// end function setLastName


double Account::getBalance() const
{
	return balance;
}

void Account::setBalance( double balanceValue )
{
	balance = balanceValue; // should validate

} 

void Account::setPassCode( int passCodeValue )
{
	passCode = passCodeValue;

}




2\bankingsystem.cpp(46) : error C2511: 'int Account::getPassCode(void) const' : overloaded member function not found in 'Account'

1> 2\bankingsystem.h(9) : see declaration of 'Account'

2\bankingsystem.cpp(68) : error C2511: 'double Account::getBalance(void) const' : overloaded member function not found in 'Account'

Now when I get these errors, I understand that these are not found in the overloaded member function. But, how do I make both constants in the overloaded member function?
Hi silversidewalkstew,

OK, I think you need a bit of reorganising here, to get rid of all your get & set functions, so that your current errors will go away.

Firstly, remember that class functions have direct access to class member variables, despite their declared access specifier. In other words, a class function has direct access to the member variables even though they might be private or protected.

Also, there is the concept of initialiser lists.

So, you can make use of these two things to get rid of all your set functions.

The constructor you have on lines 9 to 23, could look like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Account::Account( int accountNumberValue, 
				 int passCodeValue,
				 string lastNameValue, 
				 string firstNameValue, 
				 double balanceValue
 ) :  // Colon introduces the initialiser list
           accountNumber(accountNumberValue),
           passCode(passCodeValue),
           lastName(lastNameValue),
           firstName(firstNameValue),
           balance(balanceValue);
{} // no need for any code in here



It is usual practice to have the initialiser list in the same order as what is in the class declaration, You haven't shown that file, so I am not sure whether the order shown is correct or not.

You could also get rid of all your get functions as well, in main() you are using them instead of creating an object with an appropriate constructor - the code I have shown above.

Initialiser lists are better than assignment because it happens during construction of the object rather than after, and in your case avoids a bunch of getter & setter functions.

We had a huge discussion about getters & setter functions a while back, It might be worth your while to read it. It is a bit long at 7 pages, but there is some good stuff in there. In general, trivial use of them is bad, especially setters, but there are situations where they are warranted. IMO beginners should avoid routinely using them in a trivial manner.

http://www.cplusplus.com/forum/lounge/101305/


It is important to realise the difference between a setter function & an update function. The latter has code that checks & validates, as in a withdrawal function.

Now the other big concept is the idea of encapsulation. Part of that says that every function that operates on an object should be a member function of that class. So in main() functions like outputLine & getAccount should be class functions IMO.

The outputLine function is a good example of how not to use getter functions. Prefer to have a class function called PrintThisAccount say.

Also, I am a bit sceptical about your approach of over writing parts of files directly, because it could be error prone. What happens if you manage to have duplicate account numbers? You don't seem to have code that checks for that.

By making use of an appropriate STL container like std::map or std::set along with the [] operator, one can do this easily. Use of those containers might be beyond the scope of your course, but even with a std::vector it would be better.

At this level, it would be perfectly fine & much better to read all the values from a file into a std::vector say, make the modifications to the data in the vector, then write the whole vector out to a new file when finished.

The BankingSystem class should have a member which is a std::vector (if you were to use this container say) of Account objects. This class should have all the functions for : Creating, deleting, finding accounts ; while the Account class has functions for dealing with details of an Account.

Also the use of reinterpret_cast is a clue that the OO design is not as good as it could be.

And you should prefer the use of std::string over char arrays.

Now all this means a bit of work for you, but I hope you realise that it will vastly improve your code, and should help you get much better marks for your assignment. And it should give you a much better approach to the way you design your code in the future.

Hope all goes well, I look forward to helping for any other queries you may have.

Last edited on
I apologize for starting a new thread. I did not see you post on this thread. I am just a little stressed on this project. I am taking this class online and as far as online classes go, it is basically teach yourself. This class as you can probably tell by my coding has been a struggle. I appreciate you responding and helping me out. You're right, I don't want to have to redo this, but by the looks I might have to..
+1 for TheIdeasMan's extremely appropriate suggestions.

@silversidewalkstew
But, how do I make both constants in the overloaded member function?

What do you mean by this exactly? The errors you're receiving are likely caused by a mismatch between function declaration and function definition. Since you haven't provided an updated header file with the functions in question, it's hard to tell you what to correct.
EDIT* Woops, I AM silly.

Unless you've changed the definitions to match your declarations in the mean time, they should look like this:

1
2
3
int getPassCode();

double getBalance();


Which is wrong, as you are missing the const keyword in your declarations.

EDIT* Just realized this problem has already been solved in your other thread...
Last edited on
Thanks for the links and explanations too, I do appreciate that. That is helpful.
This is what I have.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

	#include <iostream> //
	#include <string>

	using namespace std;

	#include "BankingSystem.h"

	// constructor
	Account::Account( int accountNumberValue, 
					 int passCodeValue,
					 string lastNameValue, 
					 string firstNameValue, 
					 double balanceValue
	 )


	{
	 setAccountNumber( accountNumberValue );
	   setPassCode ( passCodeValue );
	   setLastName( lastNameValue );
	   setFirstName( firstNameValue );
	   setBalance( balanceValue );
	}
	// end constructor

	// return first name
		string Account::getFirstName()
		{
			return firstName;

		}// getFirstName

	// return last name
		string Account::getLastName()
		{
			return lastName;

		}// end getLastName


	int Account::getAccountNumber() 
	{
		return accountNumber;

	}
	int Account::getPassCode() const
	{
		return passCode;
	}


	//set first name
	void Account::setFirstName( string &first )
	{
		firstName = first;

	} // end function setFIrstName

	//set last name

	void Account::setLastName( string &last )
	{
		lastName = last;

	}// end function setLastName


	double Account::getBalance() const
	{
		return balance;
	}

	void Account::setBalance( double balanceValue )
	{
		balance = balanceValue; // should validate

	} 

	void Account::setPassCode( int passCodeValue )
	{
		passCode = passCodeValue;

	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef BANKING_SYSTEM_H
#define BANKING_SYSTEM_H

#include <string> // Used to allow string functions
#include <vector>
#include <iostream> 


class Account {

public:

//and here's a default constructor.
Account( int accountNumberValue, int passCode, std::string lastName, 
           std::string firstName, double balance);

  Account() {accountNumber=passCode=0; balance=0.0; firstName=" "; lastName=" ";}
  ~Account();

  void setFirstName ( std::string & );
  std::string getFirstName();

  void setLastName( std::string & );
  std::string getLastName();

  void setAccountNumber( int accountNumberValue );
  int getAccountNumber();

  void setPassCode( int passCodeValue );
  int getPassCode();
  int getPassCode() const;

  void setBalance( double balanceValue );
  double getBalance();
  double getBalance() const;


private:
  std::string firstName;
  std::string lastName;
  int accountNumber;
  int passCode;
  double balance;

};

class BankingSystem
{
public:
  BankingSystem();
  ~BankingSystem();

  Account query(int accountId);

  void addAccount();//option 1

  void deleteAccount();//option 2

  void AccountInquiry();//option 3

  void saveAccount();//option 4

  void loadAccounts();//option 5

private:
  std::vector<Account> accounts_;
};

#endif   
@silversidewalkstew

Yeah, it can be tough - I don't know what reading / learning material you have been given, but there is often a lot of misleading examples out there.

For example, everyone says that using private data members is a good idea - which is 100% correct. Now one needs an interface of public functions to manipulate the data - which is still 100% correct. But then they jump straight into having (or at least implying) getters & setters for each member variable - which is not a good idea. The reality is that one might not need any of them

This sort of thing confused me for a relatively long time - if one has public getters & setters for each member variable, then they might as well all be public !!

Any way it is all there in the Topic about getters & setters. I did a summary of important ideas on this post - which not too many people complained about - so hopefully that might mean what I said was right :

http://www.cplusplus.com/forum/lounge/101305/5/#msg546461


With the const qualifier on function declarations and their corresponding definitions:

1. The declaration and definition need to match - functions that differ only in their const qualifier are essentially a different, overloaded function.
2. The const means that nothing in the object will be altered, so one should have this for any get function or other function such as one that prints stuff for example. If it doesn't change the value of any member, then make it const.
3. Quite often, the parameters to functions should be const as well, if so, one needs to put const before each parameter that needs it. Parameters are the types & names of variables in the parentheses of a function declaration & definition, whereas arguments are the actual values sent to a function.
4. One can have const on the return value of a function as well.

With your duplicate topics, make it clear which which one should be replied to, and remove the solved symbol. Provide a link to the topic that should be used, and an explanation, in the topic that shouldn't be continued. Presumably the topic to be discontinued will be the other one, as you have code in this one.

Cheers


"This sort of thing confused me for a relatively long time - if one has public getters & setters for each member variable, then they might as well all be public !!

Any way it is all there in the Topic about getters & setters. I did a summary of important ideas on this post - which not too many people complained about - so hopefully that might mean what I said was right :

http://www.cplusplus.com/forum/lounge/101305/5/#msg546461"


Thank you so much for taking the time to explain that to me because that really makes sense and I understand where you are coming from. My (school)class was not to get so involved in classes or class development. That is really why I was having a hard time because I did not fully understand what I was doing or why I was doing it.

Like I said, I really appreciate this because you broke it down to where I can understand it. So, thank you.
No worries, pleased to help - let us know how you get on.
Pages: 12