int main()

can someone help me with error codes please.
main.cpp: In function ‘int main()’:
main.cpp:13:5: error: ‘Bank_Account::Bank_Account()’ is private
Bank_Account()
^
main.cpp:48:18: error: within this context
Bank_Account ob;
^
main.cpp:51:26: error: expected primary-expression before ‘)’ token
cin>>ob.setName(string);
^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 #include<iostream>
#include<string>
using namespace std;

class Bank_Account      //name of the class
{
    private:
    string name;        //attributes to the private so its protected
    int acct_num;
    int pin_num;
    double Balance;
    
    Bank_Account()
    {
        Balance=0;           //balance needed to intialized
    }
    
    Bank_Account  (double B)
    {
        Balance=B;
    }

    public:
    
void setName (string);    //for name to store
string getName ();   //for name to store and retrive name
void setAcctnum ();//account num to store 
double getAcctnum (double); //acct num for retrive acct number
double getBalance (double);//retrieve the balance 
bool setPIN  (double);  // to store number
double checkPIN(double); // receives a PIN number as parameter, returns TRUE if it matches the PIN in the object
void deposit(); // Receives amount of money to deposit.If this amount is valid (positive) then + to balance. Otherwise do nothing. No return value.
void  withdraw(); // Receives amount of money to withdraw. If this amount is valid(positive) then make sure there are funds to cover the withdrawl.
            //If so then subtract from balance. If not enough money then printthe message “Insufficent funds” and make no changes. No return value
   
};
void Bank_Account::setName (string Bname)
{
    name=Bname;
}
string Bank_Account::getName ()
{
return name;
}

int main()
{
    Bank_Account ob;
   
   cout<<"what is name";
   cin>>ob.setName(string);
   return 0;
}

.
1
2
3
4
5
6
7
8
int main()
{
    Bank_Account ob; // Error: you cannot create account, because the constructor is not public
   
   cout<<"what is name";
   cin>>ob.setName(string); // Error: What is a "string"? Error: cin >> void
   return 0;
}

Perhaps you should make the constructors public?

Read to string variable first. Then call setName() with that variable.
i moved constructors to public but i still have error int main()


int main()
{

Bank_Account ob;

cout<<"what is name";
cin>>ob.setName(string);
return 0;
}

main.cpp: In function ‘int main()’:
main.cpp:51:25: error: expected primary-expression before ‘)’ token
cin>>ob.setName(string);
^
As keskiverto hinted at, setName returns void (that is, it returns nothing), so you can't use it directly with cin >>.
That's not how you'd call a function anyway, I highly suggest reading http://www.cplusplus.com/doc/tutorial/functions/

1
2
3
std::string name;
cin >> name;
ob.setName(name);
Last edited on
thank you! will do , just having little trouble with Objects
Topic archived. No new replies allowed.