Hello there. I want to start off by saying thank you in advance. I'm having a problem storing an object and then searching for it later on. I try to store the Person object which is created by the function addUser() into a vector (of Person pointers). I get an error when I try to return the Person temp from the addUser() function. The error says:
"Debug Assertion Failed
_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)".
I don't want to bombard you with tons of headers and implementation files, so I will put code just what I think is necessary. If you need more, please let me know.
Dquicken.h
CODE
#include "Person.h"
using namespace std;
#ifndef DQUICKEN_H
#define DQUICKEN_H
class Dquicken{
private:
vector<Person*> users; // the users in this program
public:
Dquicken();
~Dquicken();
Person addUser(); // returns a user to add to the program
void displayMainMenu(); // displays the main menu of the program
void displaySplash(); // displays the splash screen!!!
void getNameAndPass(string&, string&); // gets a username and password for and added file
void ProgramLoop(); // program continues running until user ends it
Person findFile(string name, string how); // find a person, whether by username or name
};
#endif
Dquicken.cpp
CODE
// THIS IS DQUICKEN.CPP
#include "Dquicken.h"
#include "StringReader.h"
#include <iostream>
Dquicken::Dquicken(){
users.empty(); // what is the best way to initialize a vector?
users.clear();
}
Dquicken::~Dquicken(){
// get rid of all users
for(size_t i = 0; i < users.size(); ++i){
delete users[i];
}
users.empty();
users.clear();
}
void Dquicken::displayMainMenu(){}
Person Dquicken::addUser(){
string name = getString("name");
// get information for that person
cout << "Would you like to enter a username and password for the file?(y/n)---->";
char yorn;
cin >> yorn;
Person temp = Person(name);
if(yorn == 'y'){
// get username and password
cout << "\n\n";
string nName, nPass;
this->getNameAndPass(nName, nPass);
temp.setPassword(nPass);
temp.setUsername(nName);
}else{
cout << "\nOk. You can add that information or change it later if you load the file.";
}
return temp;
}
void Dquicken::displaySplash(){
cout << "\n\n\n\t\t\tWELCOME TO DeSOTO QUICKEN!\n\n\n"
<< "\tPress Alt and Enter to make the program go full screen\n\n\n\n\n\n\n\n\n"
<< "Created by Albert Espinal, Copyright 2008\n\n\n";
system("pause");
}
void Dquicken::ProgramLoop(){
displaySplash();
system("cls");
Person* currentFile = new Person();
displayMainMenu();
char menu_choice;
cout << endl
<< "What would you like to do? (1-4)--->";
cin >> menu_choice;
while(menu_choice != '4'){
// if the user wants to load a file
if(menu_choice == '1'){
//find the file
}
// if the user wants to add a file
if(menu_choice == '2'){
Person addMe = addUser();
users.push_back( &addMe );
cout << "\n\nUser added." << endl;
cout << "\n";
// pause before going back to main menu
cout << "\n\n";
system("pause");
}
// if the user wants to delete a file
if(menu_choice == '3'){}
// start over
system("cls");
displayMainMenu();
cout << "What would you like to do? (1-4)--->";
cin >> menu_choice;
}
// user wants to leave, so leave
cout << "\nExiting.\n\n";
delete currentFile;
exit(1);
}
Also, this is not a homework assignment. This is my own personal project.
Thanks again. Peace.