here's the deal. i tried implementing classes in the way that i was questioning the other day, and here's the code i got:
Code:
#ifndef LOGIN_H
#define LOGIN_H
#include <iostream>
#include <fstream.h>
#include <string>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
class BankClass
{
private:
double balance;
public:
class BalanceOps
{
public:
BalanceOps ()
{
balance = 0.0;
}
void credit (double amt)
{
balance += amt;
}
void debit (double amt)
{
balance -= amt;
}
double getBalance ()
{
return balance;
}
void setBalance (double amt)
{
balance = amt;
}
};
class FileOpsBank
{
private:
string username;
string usersdir;
double balance;
public:
FileOpsBank (string user, string dir)
{
username = user;
usersdir = dir;
}
void loadBalance (string filename)
{
ifstream infile;
string tempstr;
infile.open(filename.c_str());
getline (infile, tempstr);
infile.close ();
balance = strtod (tempstr.c_str(), NULL);
}
void saveBalance (string filename)
{
ofstream outfile;
outfile.open (filename.c_str());
outfile << balance;
outfile.close ();
}
};
};
int main ()
{
BankClass::BalanceOps banker;
double amt;
banker.setBalance (2.25);
cin >> amt;
banker.credit (amt);
amt = banker.getBalance ();
cout << amt;
system ("pause");
return 0;
}
#endif
the main function here was just to test the class, not my actual program. Anyways, when i compile the code as is with Dev C++, it says "linker error: undefined reference to BankClass::balance". What is going on here? oh, and i know i have a bunch of unneccesary libraries included, i promise, im using them later.