c++ - Unhandled exception within my menu -


i getting unhandled exception in code , have no idea why. first time using more 1 class together.

at moment trying put user input string class. trying input user input string called name in class below

#ifndef ship_h #define ship_h #include "applicationmenu.h" #include <string> class ship { public:     ship(void);     ~ship(void);      std::string _size;     std::string _shipname;     std::string name; };  #endif 

into following function ran in main

#include "applicationmenu.h" #include "ship.h" #include <string> #include <sstream>  class ship;  #include <iostream>  using namespace std;  applicationmenu::applicationmenu(void) { userchoice = 0; }   applicationmenu::~applicationmenu(void) { }    void applicationmenu::displaymenu() {       cout << "welcome port." << endl << "please select 1 of         following options : " << endl         << "1: dock ship" << endl;     cin >> userchoice;     switch (userchoice)     {     case 1:          ship*   ship;          ship->name;           cout << "please enter name of ship wish dock: ";         cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');         getline(cin, ship->name);          cout << ship->name;         break;     } } 

can please advise why getting error?

edit:

this error because of uninitialised pointer due lack of knowledge pointers in c++. although answered community link prove helpful future viewers. http://www.cplusplus.com/doc/tutorial/pointers/

you have uninitialized pointer ship* ship;. either need use ship* ship = new ship(); or declare ship ship ship;


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -