Won't Compile, Didnt Touch Anything (Classes)

I had this working completely fine earlier and now ever since I reopened my project it doesnt compile anymore and I have no idea why. I'm using Netbeans and have tried reparsing the project several times.

main (Yes header file is included)
1
2
3
4
5
6
7
 int main (){
  cout << boolalpha << setprecision(2) << fixed;
  double query;
  bool result;
  Bank bnk("Bank of Evil");
  cout << "Bank Name:"<<bnk.bank_name()<<endl;
  cout << "Bank ID:"<<bnk.bank_id()<<endl;


bank.cpp (Yes, header is included)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Bank::Bank(string name){ //Constructor for the bank, takes in a string for the bank name.
    name_ = name;
    bank_id_ = random_ID();
}

string Bank::bank_name() //Allows the banks name to be printed
{
    return this->name_;
}

long Bank::random_ID() //Generates the bank's ID number
{
    long random;
    long lower = 10000;
    long upper = 99999;
    
    random = rand() % upper + lower;
    return random;
}

long Bank:: bank_id() //Allows the bank ID to be printed
{
    return this->bank_id_;
}


bank.h
1
2
3
4
5
6
7
8
9
10
class Bank{
   string name_;
   long bank_id_;
  
   Bank (string);
    
   friend string bank_name();
   friend long random_ID();
   friend long bank_id();
};


Errors
1
2
3
4
5
6
proj09-bank.h: In function ‘int main()’:
In file included from main.cpp:20:0:
proj09-bank.h:32:4: error: ‘Bank::Bank(std::string)’ is private
main.cpp:26:26: error: within this context
main.cpp:27:29: error: ‘class Bank’ has no member named ‘bank_name’
main.cpp:28:27: error: ‘class Bank’ has no member named ‘bank_id’


Thanks :)
Last edited on
Maybe you should take a cue from the error messages and not make every member private.

As it also indicates, bank_name, bank_id and random_ID are not members of Bank. They are freestanding functions that are friends of the Bank class.
Got it, ty :)
Topic archived. No new replies allowed.