Solved

Strange runtime error in simple program

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
The dreaded error 1935 with VC++ 2008 Redistributable 12 88
Getting IP address 8 71
Header of docx file 17 95
c++ reading data from file into two dimensional array 3 92
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

947 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

22 Experts available now in Live!

Get 1:1 Help Now