Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bad Ptr

Status
Not open for further replies.

benkmann

ISP
Jun 2, 2006
10
0
0
US
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
 
0xccc implies that the value has not yet been assigned. You probably haven't initialized the parameter customer.
 
You don't show the code for the constructor of struct CustomerList. Be sure it initialises customer and next to NULL, other wise they are pointing to never never land as the 0xcccccccc indicates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top