Because of the way he's coded the constructor, he can actually assign values on creation on the object, i.e.
CustomerAccount customerAccount1( 234 );
@isenhart
When you want to pass variables to functions, you've already declared that you will be passing an 'int', so you don't need to have
( int balance )
within main.
Also, in main, you haven't yet declared a variable called
balance
.
Depending on where you will get your data for that variable, you could do something like the following:
1 2 3 4 5
|
int balance = 0;
std::cout << "Please enter balance: "
std::cin >> balance;
customerAccount1( balance );
|
Also, in the
int CustomerAccount::CustomerAccount( int balance )
function, instead of calling another function to assign the data for
accountResult
, you could just write:
accountResult = balance;
. Although, you don't have a variable called
accountResult
within the class?
You also don't have a destructor, not sure if that will throw any errors though.
And could someone tell me the difference of these two? I always do the first version.
1 2 3 4 5 6 7
|
//Constructor
foo( int integer = 0 );
foo::foo( int i )
{
integer = i;
}
|
...And...