Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Strange runtime error in simple program

Posted on 2002-04-21
3
Medium Priority
?
193 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

773 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