Is it possible to call a method from main if it is private? If not, how would it be possible?

后端 未结 4 966
日久生厌
日久生厌 2021-01-29 15:33

I am trying to get this program to start running but currently I just get errors. I am not sure how to get this to work. If I change the class SavingsAccount to public it should

4条回答
  •  臣服心动
    2021-01-29 16:13

    Well by default member functions are private, so you can always add them into public as follows:

    class SavingsAccount
    {
        private:
        int accountType;
        string ownerName;
        long ssn;
    public:
        double accountClosurePenaltyPercent, accountBalance;
        void Information();
        inline double AccountClosureLoss()
        {
            return (accountBalance * accountClosurePenaltyPercent);
        }
        void OutputInformation();
    };
    

    You will now be able to call them from the main.

提交回复
热议问题