Hey all,
So I'm attempting to re-write a former program with dynamic linked lists. It compiles fine, but crashes soon into run-time. Here's the error it gives me for a class "CustomerAccount", that has private members _username, _password, and AccountList*:
customer 0x0012faf8 {_username=<Bad Ptr> _password=<Bad Ptr> _accounts=0xcccccccc }
What does <Bad Ptr> mean?
Thank you! (I have attached some of the code below):
--------Bank.cpp-----------
...
void Bank::addCustomerAccount(CustomerAccount* customer) {
CustomerList* next = _customers;
CustomerList* New = new CustomerList();
// Sets new customer element to customer
New->customer = customer;
New->next = NULL;
// Sets next to point to last element in list
while (next != NULL && next->next != NULL) {
next = next->next;
}
// Places customer acct. at end of list or at beginning if list is empty
if (next) {
next->next = New;
}
else {
_customers = New;
}
}
CustomerAccount* Bank::getCustomerAccount(string username) {
CustomerList* tempPtr = _customers;
while (tempPtr != NULL) {
//if (tempPtr->customer->getUsername() == username) {
if ((*tempPtr).customer->getUsername() == username) {
return tempPtr->customer;
}
else {
tempPtr = tempPtr->next;
}
}
return NULL;
}
....
----------------------------End------------------
-----------------------CustomerAccount.h---------
class CustomerAccount {
public:
// we need a default ructor for array of accounts
CustomerAccount();
// create an account with the complete information
CustomerAccount(string username, string password);
// retrieve the user name
string getUsername();
// check the password, return false if not match
//
// we don't have a getPassword() member function
// since you don't want others to know the password
bool checkPassword(string password) ;
// add a new account
Account& addAccount(Account& account);
// get the account with the given identifier
Account* getAccount(int accountId);
// get all accounts
AccountList* getAccounts() ;
private:
string _username;
string _password;
//AccountArray _accounts;
AccountList* _accounts;
//void append(Account newAccount);
};
struct CustomerList
{
CustomerAccount* customer; // the value
CustomerList* next; // the link to the next element
CustomerList();
}; // struct CustomerList
So I'm attempting to re-write a former program with dynamic linked lists. It compiles fine, but crashes soon into run-time. Here's the error it gives me for a class "CustomerAccount", that has private members _username, _password, and AccountList*:
customer 0x0012faf8 {_username=<Bad Ptr> _password=<Bad Ptr> _accounts=0xcccccccc }
What does <Bad Ptr> mean?
Thank you! (I have attached some of the code below):
--------Bank.cpp-----------
...
void Bank::addCustomerAccount(CustomerAccount* customer) {
CustomerList* next = _customers;
CustomerList* New = new CustomerList();
// Sets new customer element to customer
New->customer = customer;
New->next = NULL;
// Sets next to point to last element in list
while (next != NULL && next->next != NULL) {
next = next->next;
}
// Places customer acct. at end of list or at beginning if list is empty
if (next) {
next->next = New;
}
else {
_customers = New;
}
}
CustomerAccount* Bank::getCustomerAccount(string username) {
CustomerList* tempPtr = _customers;
while (tempPtr != NULL) {
//if (tempPtr->customer->getUsername() == username) {
if ((*tempPtr).customer->getUsername() == username) {
return tempPtr->customer;
}
else {
tempPtr = tempPtr->next;
}
}
return NULL;
}
....
----------------------------End------------------
-----------------------CustomerAccount.h---------
class CustomerAccount {
public:
// we need a default ructor for array of accounts
CustomerAccount();
// create an account with the complete information
CustomerAccount(string username, string password);
// retrieve the user name
string getUsername();
// check the password, return false if not match
//
// we don't have a getPassword() member function
// since you don't want others to know the password
bool checkPassword(string password) ;
// add a new account
Account& addAccount(Account& account);
// get the account with the given identifier
Account* getAccount(int accountId);
// get all accounts
AccountList* getAccounts() ;
private:
string _username;
string _password;
//AccountArray _accounts;
AccountList* _accounts;
//void append(Account newAccount);
};
struct CustomerList
{
CustomerAccount* customer; // the value
CustomerList* next; // the link to the next element
CustomerList();
}; // struct CustomerList