Solved

Strange runtime error in simple program

Posted on 2002-04-21
3
174 Views
Last Modified: 2010-04-02
this is just a fairly simple program i wrote for school
but i am getting a strange error during runtime
from a list of 7 options, when i choose 3 of them the program crashes in windows and gives a core dump in unix
these 3 are choice #2 #4 #6. the code for each of them is quite similar no obivious reason for these errors
is there some kind of pattern? everyother choice seems to suffer from this. i am using a switch statement in the main function to call the appropriate class member functions.

the code is rather long to post here so you can access the zip file containing all the files here:
http://gdstudios.hypermart.net/code.zip

p.s. some of the functions are left as stubs, that was intentional
0
Comment
Question by:grfik
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
LoungeLizard earned 100 total points
ID: 6958608
You use pointers without first initialising them! Your main should look something like:

int main()
{
   int choice;
   Triangle *t = new Triangle;
   RightTriangle *rt = new RightTriangle;
   Quads *q = new Quads;
   Parallelogram *p = new Parallelogram;
   Rhombus *r = new Rhombus;
   Rectangle *rect = new Rectangle;
   Square *s = new Square;
   
   do
   {
      displayMenu();
      cin >> choice;

      switch(choice)
      {
         case 1:
            t->getInfo();
            t->output();
            break;
         case 2:
            rt->getInfo();
            rt->output();
            break;
         case 3:
            q->getInfo();
            q->output();
            break;
         case 4:
            p->getInfo();
            p->output();
            break;
         case 5:
           
            r->getInfo();
            r->output();
            break;
         case 6:
           
            rect->getInfo();
            rect->output();
            break;
         case 7:
           
            s->getInfo();
            s->output();
            break;
         case 0:
            cout << "Good Bye\n";
            break;
         default:
            cout << "Error!\n";
            return 1;
      }// switch

   } while(choice != 0);

   return 0;
}
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6958612
You could still put the new's inside the switch statement, if you want to create new variables every time the switch is executed.
0
 

Author Comment

by:grfik
ID: 6959060
umm i knew there would be a simple solution, thx loungelizard
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now