I am writing a program with several classes, a number of the classes create vectors of the other classes. This info probably isn't needed to help with my question but there it is.
The problem seems to be in the Stack.h file which is here
#ifndef STACK_H
#define STACK_H
#include <iostream>
#include <string>
#include <vector>
#include "Shelf.h"
using namespace std;
class Stack
{
private:
int stackWeight; //changing this to double causes a seg fault?
int numOfShelves;
string firstBook;
string lastBook;
int numOfBooks;
vector<Shelf> shelves; //create a vector of shelves
public:
Stack();
//~Stack(); //deconstructor
int getNumOfBooks();
double getStackWeight();
string getFirstBook();
string getLastBook();
void addShelf();
void removeShelf();
void addBookToStack(string s, string i, string t, string y);
};
#endif
the constructor implementation is
Stack::Stack() //Stack constructor
{
cout<<"stack created\n";
shelves.push_back(Shelf()); //add 2 shelves
shelves.push_back(Shelf());
stackWeight = 2.0; //weight of 2 empty shelves.
numOfShelves=2;
firstBook="null";
lastBook="null";
}
I'm early stages with writing this so none of the other functions are being called.
This all compiles and runs ok, up to this point, but I really need the private variable stackWeight to be of type double but for some reason this change is resulting in the error 'segmentation fault (core dumped)'
I have no idea why this is happening, any tips would be greatly appreciated.

New Topic/Question
Reply




MultiQuote



|