Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Mistaking a string for a char
    text
    copied!<p>I'm relatively new to C++, and having an issue passing a string. I have 2 constructors for a class, Transaction." One constructor accepts a string and a double as its parameters, while the other accepts just a string.</p> <p>When I attempt to pass the lines below, I get an error, saying:</p> <pre><code>no matching function for call to 'Account::addTransaction(const char [14])' </code></pre> <p>or</p> <pre><code>no matching function for call to 'Account::addTransaction(const char [11], double&amp;)' </code></pre> <p>I know that there's no matching function, because I'm passing a string! Here's what I'm passing in:</p> <pre><code>bank.getAccount(index).addTransaction("Close Account"); bank.getAccount(index).addTransaction("Withdrawal", amount_to_withdraw); </code></pre> <p>I don't know how to make it any more explicit that the first parameter is a string. Any advice would be greatly appreciated.</p> <p>Thanks, Adam</p> <p>Updating per @g24l 's request:</p> <p>Here is the Transaction Class:</p> <pre><code>#ifndef TRANSACTION_H #define TRANSACTION_H #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; class Transaction { private: string transType; double transAmount; /* public constructors: * 1st constructor is the default constructor * 2nd constructor is for non-monetary transactions * 3rd constructor is for transactions involving money */ public: Transaction() { transType = ""; } Transaction(string tType) { transType = tType; } Transaction(string tType, double tAmount) { transType = tType; transAmount = tAmount; } void setTransType(string); void setTransAmount(double); string getTransType() const; double getTransAmount() const; }; #endif /* TRANSACTION_H */ </code></pre> <p>In the Account class, which uses dynamic memory allocation for an array of transactions, I have:</p> <pre><code>class Account{ private: Depositor depositor; int accountNum; string accountType; double accountBalance; string accountStatus; Transaction *transptr; int numTransactions; //number of transactions public: // public member functions prototypes // Constructors /* Account default constructor: * Input: * Depositor() - calls the default depositor constructor * Process: * sets object's data members to default values * Output: * object's data members are set */ Account() { //cout &lt;&lt; "Account default constructor is running" &lt;&lt; endl; Depositor(); accountNum = 0; accountType = ""; accountBalance = 0.0; accountStatus = "open"; transptr = new Transaction[100]; numTransactions = 0; } </code></pre> <p>I'm wondering if, when I declare the array of Transactions, it fills in all of the Transactions with the default constructor parameters. When I "add" a transaction I'm really writing over the existing transaction.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload