Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to declare a member-object in C++
    primarykey
    data
    text
    <p>I'm trying to declare a member-object in a class in C++, like so: </p> <pre><code>class bankAccount { public: bankAccount(int, int, int, string, int); private: bankBranch homeBranch; }; bankAccount::bankAccount(int accountNumber, int accountBalance, int homebsbnumber, string homeaddress, int homepostcode) : homeBranch(homebsbnumber, homeaddress, homepostcode) {} class bankBranch { public: /** bankBranch(const int&amp; bsbNumber, const string&amp; address, const int&amp; postCode) { this-&gt;bsbNumber = bsbNumber; this-&gt;address = address; this-&gt;postCode = postCode; }; **/ bankBranch(int, string, int); void setPostCode() { cout &lt;&lt; "Please type in the postal code of your bankBranch: " &lt;&lt; endl; cin &gt;&gt; postCode; } void setBsbNumber() { cout &lt;&lt; "Please type in the BSB Number of your bankBranch: " &lt;&lt; endl; cin &gt;&gt; bsbNumber; } void setAddress() { cout &lt;&lt; "Please type in the address of your bankBranch " &lt;&lt; endl; cin &gt;&gt; address; } // Return methods for bsb number, address and post code int getBsbNumber() { return this-&gt;bsbNumber; } string getAddress() { return this-&gt;address; } int getPostCode() { return this-&gt;postCode; } private: int bsbNumber; string address; int postCode; }; bankBranch::bankBranch(int bsbnum, string bankaddress, int bankpostcode) { bsbNumber = bsbnum; address = bankaddress; postCode = bankpostcode; } </code></pre> <p>I am getting these erros:</p> <ul> <li>sytax error : missing ';' before identifier 'homeBranch'</li> <li>missing type specifier - int assumed (confused because it is obviously an object?)</li> <li>'bankAccount' : illegal member initialization: 'homebranch' is not a base or member </li> </ul> <p>I have tried many things and cannot seem to fix these errors, could anyone provide me with some insight on how to properly add the member-object bankBranch homeBranch to the class bankAccount? And how to properly use initialization lists.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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