Solved

Strange runtime error in simple program

Posted on 2002-04-21
3
189 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 268
how to convert c++ code to Android App 3 130
Exception thrown at 0x00007FFD5BC81F28 7 55
FMX TCameraComponent Problem 2 92
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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