I haven't manually called either. Could using vectors and strings set that off?

11-16-2008

tabstop

Did you call a destructor explicitly?

11-16-2008

JamesKidder

here is most of the relavent code:

Code:

//THIS IS THE HEADER FILE
#include<string>
#include<fstream>
#include<vector>
//I know, don't do this in a header, but at this point I am just trying to get it to work
using namespace std;
class item
{
public:
/*
This constructor accepts a string and creates an object with that name
@parameter- inputName: The name of the of the item
*/
item(string inputName);

/*
This function intializes a blank object
*/
item();
/*
This function returns the name of the item
@return: The name of the item
*/
string getName() const;
/*
This function outputs the members of item
@param stream: The stream the output is being written to
@param inputItem: The item that is being written to the stream
@return: The outputstream
*/
friend ostream &operator<<(ostream &stream, item inputItem);
/*
this function outputs the size of the name string followed by the name of the item to the stream given
@param outputStream: The stream to be written to
*/
void save(ofstream &outputStream);
/*
This function inputs the size of the name vector and then loads the name vector
@param inputStream: the file stream to be read from
@return: Whether the load was successful or not
*/
bool load(ifstream &inputStream);

/*
This function constructs an item with the contents of another item
@param inputItem: The item to be copied from
*/
// item(item const& inputItem);

/*
This operator assigns the values of another item to itself and returns a pointer to itself
@param inputItem: The item the values are being taken from
@return: a pointer to this item
*/
// item& operator = (item &inputItem);
private:
string name;
};

/*
This constructor accepts a string and creates an object with that name
@parameter- inputName: The name of the of the item
*/
item::item(string inputName)
{
name=inputName;
}

/*
This function intializes a blank object
*/
item::item()
{
}

/*
This function returns the name of the item
@return: The name of the item
*/
string item::getName() const
{
return name;
}
/*
This function outputs the members of item, first the length of the vector and then the vector name
@param stream: The stream the output is being written to
@param inputItem: The item that is being written to the stream
@return: The outputstream
*/
ostream &operator<<(ostream &stream, item inputItem)
{
stream<<inputItem.name.length() << inputItem.name;
return stream;
}

/*
this function outputs the size of the name string followed by the name of the item to the stream given
@param outputStream: The stream to be written to
*/
void item::save(ofstream &outputStream)
{
outputStream << *this;
}
/*
This function inputs the size of the name vector and then loads the name vector
@param inputStream: the file stream to be read from
@return: Whether the load was successful or not
*/
bool item::load(ifstream &inputStream)
{
int i;
char ch;
if(inputStream)
{
inputStream>>i;
}
else
{
return false;
}
for(int ii=0; ii<i && inputStream; ii++)
{
inputStream.get(ch);
name.push_back(ch);
}
if(i!=name.length())
{
return false;
}
else
{
return true;
}
}

/*
This function constructs an item with the contents of another item
@param inputItem: The item to be copied from
*/
/*
item::item(item const& inputItem)
{
name=inputItem.getName();
}
*/
/*
This operator assigns the values of another item to itself and returns a pointer to itself
@param inputItem: The item the values are being taken from
@return: a pointer to this item
*/
/*
item& item::operator = (item &inputItem)
{
name=inputItem.getName();
return this*;
}
*/

//This is a menu made of items
class itemMenu
{
public:
/*
This function loads all of the items in the file and saves them in the listOfItems
@Param inputStream: The file stream that the items are to be read from
*/
itemMenu(ifstream &inputStream);
/*
This loads an empty menu
*/
itemMenu();
/*
This function adds an item to the listOfItems
@param inputItem: the item to be added
*/
void addItem(item inputItem);
/*
This function erases the item with the given name in the listOfItems
@param itemName: The name of the item to be deleted
*/
void deleteItem(string itemName);

/*
This function erases the last item on the menu
*/
void deleteItem();

/*
This function couts all of the items in the listOfItems
*/
void showItems();

/*
This function saves all of the items in the listOfItems
@param outputStream: The file stream for the items to be saved to
*/
void saveMenu(ofstream &outputStream);

/*
This function returns a copy of an item in the menu and a blank item if the index is wrong
@param inputIndex: The index of the item to be accessed
*/
item getItem(int inputIndex);
private:
vector<item> listOfItems;

};

/*
This function loads all of the items in the file and saves them in the listOfItems
@Param inputStream: The file stream that the items are to be read from
*/
itemMenu::itemMenu(ifstream &inputStream)
{
item null;
listOfItems.push_back(null);
while(listOfItems[listOfItems.size()-1].load(inputStream))
{
listOfItems.push_back(null);
}
listOfItems.pop_back();
}
/*
This loads an empty menu
*/
itemMenu::itemMenu()
{
}
/*
This function adds an item to the listOfItems
@param inputItem: the item to be added
*/
void itemMenu::addItem(item inputItem)
{
listOfItems.push_back(inputItem.getName());
}
/*
This function erases the item with the given name in the listOfItems
@param itemName: The name of the item to be deleted
*/
void itemMenu::deleteItem(string itemName)
{
for(int i=0; i<listOfItems.size(); i++)
{
if(listOfItems[i].getName()==itemName)
{
listOfItems.erase(listOfItems.begin()+i-1);
}
}
}

/*
This function erases the last item on the menu
*/
void itemMenu::deleteItem()
{
listOfItems.pop_back();
}

/*
This function saves all of the items in the listOfItems
@param outputStream: The file stream for the items to be saved to
*/
void itemMenu::saveMenu(ofstream &outputStream)
{
for(int i=0; i<listOfItems.size(); i++)
{
listOfItems[i].save(outputStream);
}
}

/*
This function returns a copy of an item in the menu and a blank item if the index is wrong
@param inputIndex: The index of the item to be accessed
*/
item itemMenu::getItem(int inputIndex)
{
if(inputIndex<listOfItems.size())
{
return listOfItems.at(inputIndex);
}
else
{
item noName;
return noName;
}
}

class burgerMan
{
public:
/*
This function load's burgerMan's menu from the file so he can take orders
@param inputStream: the file stream with the menu items
*/
burgerMan(ifstream &inputStream);
/*
This function takes in a natural language restarant order and extracts the which order types are required and how much of each
@param inputString: The natural langauge request
@return: The order
*/
string takeOrder(string inputString);
private:
itemMenu menu;
};

ifstream streamer("orderMenu");
burgerMan mani(streamer);
mani.takeOrder("This is a sentice. this not. Can you tell the difference?");
cout <<"\n";
return 0;
}

The takeOrder function of the burgerMan class has most of the code that actually get exicuted

11-16-2008

tabstop

Your takeOrder is supposed to return a string, but doesn't. Once I fix that to return void (VS wouldn't even let me compile it otherwise), I don't get a crash. Maybe I'll wander over to the mac, which is more like the setting you're in, and see whether that makes a difference.

Edit: Same deal here -- I get a segmentation fault if I run your code; if I change takeOrder to return void, everything's fine. Apparently it's the trying to destruct a string that you didn't return that is causing the problems. So if you do intend to return a string, later, then for now just return something (anything); otherwise change it to void. And read your compiler warnings!

11-16-2008

JamesKidder

That did it. Wow, GCC compiled that without error. Thanks.

11-16-2008

tabstop

Well, if by without error you mean:

Code:

temp.cpp: In member function ‘bool item::load(std::ifstream&)’:
temp.cpp:129: warning: comparison between signed and unsigned integer expressions
temp.cpp: In member function ‘void itemMenu::deleteItem(std::string)’:
temp.cpp:251: warning: comparison between signed and unsigned integer expressions
temp.cpp: In member function ‘void itemMenu::showItems()’:
temp.cpp:273: warning: comparison between signed and unsigned integer expressions
temp.cpp: In member function ‘void itemMenu::saveMenu(std::ofstream&)’:
temp.cpp:285: warning: comparison between signed and unsigned integer expressions
temp.cpp: In member function ‘item itemMenu::getItem(int)’:
temp.cpp:297: warning: comparison between signed and unsigned integer expressions
temp.cpp: In member function ‘std::string burgerMan::takeOrder(std::string)’:
temp.cpp:345: warning: comparison between signed and unsigned integer expressions
temp.cpp:366: warning: comparison between signed and unsigned integer expressions
temp.cpp:340: warning: unused variable ‘numberActive’
temp.cpp:371: warning: control reaches end of non-void function

(I put everything in one file, so your line numbers may vary.) But the one at the end is the big one (this time).