samedi 28 février 2015

how can a void function be called to the main, if there are no returns?


I wanted to create a function that retrieves all the information from previous functions within the same Class, and prints the values that were returned in the format of a bunch of cout statements, there is nothing for me to return in this PrintStatement() function, so I would create a void function, correct? My issue is in the int main(), I cannot cout a void function.


this is my account header file, and the function piece from my account.cpp file.



class Account {

public:
//Object constructor
Account(char firstName[], char lastName[], char sinNumber[], double balance, int accountType, int transactions);

//Object operations
double DepositAmt(double amount);
double WithdrawAmt(double amount);
void PrintStatement();
double getFinalBalance(double fbal);
string getAccountType();
double getTransactions (double Deposit, double Withdraw);

private:
//Object properties
char firstName[255];
char lastName[255];
char sinNumber[255];
double balance;
int accountType;
int transactions;
};


void Account::PrintStatement()
{

cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "SIN Number: " << sinNumber << endl;
cout << "Account Type: " << accountType << endl;
cout << "Final Balance: " << balance << endl;
cout << "Transactions: " << transactions << endl;


};


the global variables have already been initialized.


What I've tried:


I originally tried to cout << account.PrintStatement() << endl; however I get an error C2679 (binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)


I thought maybe changing things to apply to a string function instead would work, but instead I get a bunch of int conversion errors etc.


I'm unsure of what to do.


I am required to put these in a function just to be clear.


I tried using this question http://ift.tt/1DnkUJZ to help me, it made sense that the poster was using a reference, but I do not have that. Is there another way?




Aucun commentaire:

Enregistrer un commentaire