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

后端 未结 4 967
日久生厌
日久生厌 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 15:50

    You must declare an instance of the SavingsAccount class first. For example:

    int main()
    {
        SavingsAccount account;
        account.Information();
    
        ...
    
        return 0;
    }
    

    Additionally, yes, the methods of the class that you want to call must be public.

提交回复
热议问题