473,770 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with this error

9 New Member
test has exited due to signal 10 (SIGBUS).

This is the circle class
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream.h>
  3.  
  4.  
  5. class Shape
  6. {
  7.   private:
  8.      int x_Center, y_Center;
  9.  
  10.   public:
  11.     Shape()
  12.     {
  13.     cout <<"In defualt constructer";
  14.     }
  15.     Shape(Shape& sh)
  16.     {
  17.     x_Center=sh.x_Center;
  18.     y_Center=sh.y_Center;
  19.     }
  20.      // Constructors
  21.      Shape(int cx, int cy)
  22.     {
  23.         x_Center=cx;
  24.         y_Center=cy;
  25.     }
  26.  
  27.      // Member functions
  28.      int getCenter_X();
  29.      int getCenter_Y();
  30.      virtual void draw()=0;
  31. };
  32.  
  33. class Rectangle : public Shape
  34. {
  35. private:
  36.     int length,width;
  37.  
  38.  public:
  39.  
  40.   // Default constructor
  41.   Rectangle (Rectangle& r) : Shape(r)
  42.     {
  43.     length=r.length;
  44.     width=r.width;
  45.     }
  46.  
  47.   // Constructor
  48.   Rectangle (int cx, int cy,int l,int w) : Shape(cx, cy)
  49.     {
  50.     length=l;
  51.     width=w;
  52.       cout << "In Rectangle constructor" << endl;
  53.     }
  54.  
  55.  
  56.  
  57.     // Destructor
  58.     ~Rectangle ()
  59.       {
  60.     cout << "In Rectangle destructor" << endl;
  61.       }
  62.  
  63.     void draw()
  64.     {
  65.     cout <<"In drawing of Rectangle"<<endl;
  66.     }
  67.  
  68.     Rectangle & operator=(const Rectangle &obj)
  69.     {
  70.     int cx=this->getCenter_X();
  71.     int cy=this->getCenter_Y();
  72.     int length=this->length;
  73.     int width=this->width;
  74.     Rectangle newRect(cx,cy,length,width);
  75.  
  76.     return newRect;
  77.     }
  78.     // Methodds
  79.     void printAllValues();
  80. };
  81.  
  82. class Circle : public Shape
  83. {
  84. private:
  85. int diameter;
  86.  
  87.  public:
  88.  
  89.   // Default Constructor
  90.   Circle ()
  91.     {
  92.       cout << "In the default constructor of Circle" << endl;
  93.     }
  94.  
  95.     Circle (Circle& r) : Shape(r)
  96.     {
  97.     diameter=r.diameter;
  98.     }
  99.   // Constructor
  100.   Circle (int cx, int cy, int dia) : Shape (cx, cy)
  101.     {
  102.       cout << "In Circle Constructer" << endl;
  103.       diameter=dia;
  104.     }
  105.  
  106.     // Destructor
  107.     ~Circle ()
  108.       {
  109.     cout << "In Circle destructor" << endl;
  110.       }
  111.       void draw()
  112.     {
  113.     cout <<"In drawing of Circle"<<endl;
  114.     }
  115.     Circle & operator=(const Circle &obj)
  116.     {
  117.     int cx=this->getCenter_X();
  118.     int cy=this->getCenter_Y();
  119.     int diameter=this->diameter;
  120.      Circle newCircle(cx,cy,diameter);
  121.  
  122.     return newCircle;
  123.     }
  124.     // Methods
  125.     void printAllValues();
  126. };
  127.  
This is the tester
Expand|Select|Wrap|Line Numbers
  1. #include "shape.h"
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. Rectangle r(10,10,10,10);
  7. r.draw();
  8. Circle aCircle(10,10,10);
  9. aCircle.draw();
  10. cout <<"Rectangle" <<endl;
  11. r.printAllValues();
  12. cout <<endl <<"Circle" <<endl;
  13. aCircle.printAllValues();
  14. cout<< endl <<"Constucting copy of Rectangle" <<endl;
  15. Rectangle r2(r);
  16. r2.printAllValues();
  17. cout << endl <<"Constructing copy of Circle" <<endl;
  18. Circle aNotherCircle(aCircle);
  19. aNotherCircle.printAllValues();
  20.  
  21. cout << endl;
  22. Rectangle rect;
  23. rect=r;
  24. rect.printAllValues()
  25.  
  26. return 0;
  27. }
Why is this Error happening and what does it mean?
Oct 22 '07 #1
3 1328
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
There are couple of issues with the code
1)The code for overloading = operator is wrong
You are creating a stack object and returning it.
It shuld be like this
Expand|Select|Wrap|Line Numbers
  1. Rectangle & operator=(const Rectangle &obj)
  2. {
  3.   //fill the this ooj with values from obj and return this lik
  4.    cx=obj.getCenter_X();
  5.   //first check for this is = to obj
  6.   return *this.
  7. }
  8.  
2)Same is the case with Circle & operator=(const Circle &obj)

Correct these errors and try to run the code.

Raghuram
Oct 22 '07 #2
hjast
9 New Member
Here is the updated code. It still gives a SIGBUS error and I don't know why.


Main code

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream.h>
  3.  
  4.  
  5. class Shape
  6. {
  7.   private:
  8.      int x_Center, y_Center;
  9.  
  10.   public:
  11.     Shape()
  12.     {
  13.     cout <<"In defualt constructer";
  14.     }
  15.     Shape(Shape& sh)
  16.     {
  17.     x_Center=sh.x_Center;
  18.     y_Center=sh.y_Center;
  19.     }
  20.      // Constructors
  21.      Shape(int cx, int cy)
  22.     {
  23.         x_Center=cx;
  24.         y_Center=cy;
  25.     }
  26.  
  27.      // Member functions
  28.      int getCenter_X();
  29.      int getCenter_Y();
  30.      void setCenter_X(int i)
  31.      {
  32.      x_Center=i;
  33.      }
  34.      void setCenter_Y(int i)
  35.      {
  36.      y_Center=i;
  37.      }
  38.      virtual void draw()=0;
  39. };
  40.  
  41. class Rectangle : public Shape
  42. {
  43. private:
  44.     int length,width;
  45.  
  46.  public:
  47.  
  48.   // Default constructor
  49.   Rectangle (Rectangle& r) : Shape(r)
  50.     {
  51.     length=r.length;
  52.     width=r.width;
  53.     }
  54.  
  55.   // Constructor
  56.   Rectangle (int cx, int cy,int l,int w) : Shape(cx, cy)
  57.     {
  58.     length=l;
  59.     width=w;
  60.       cout << "In Rectangle constructor" << endl;
  61.     }
  62.  
  63.  
  64.  
  65.     // Destructor
  66.     ~Rectangle ()
  67.       {
  68.     cout << "In Rectangle destructor" << endl;
  69.       }
  70.  
  71.     void draw()
  72.     {
  73.     cout <<"In drawing of Rectangle"<<endl;
  74.     }
  75.  
  76.     Rectangle & operator=(Rectangle &obj)
  77.     {
  78.     int x=obj.getCenter_X();
  79.     int y=obj.getCenter_Y();
  80.     this->setCenter_X(x);
  81.     this->setCenter_Y(y);
  82.     this->length=obj.length;
  83.     this->width=obj.width;
  84.     return *this;
  85.     }
  86.     // Methodds
  87.     void printAllValues();
  88. };
  89.  
  90. class Circle : public Shape
  91. {
  92. private:
  93. int diameter;
  94.  
  95.  public:
  96.  
  97.   // Default Constructor
  98.   Circle ()
  99.     {
  100.       cout << "In the default constructor of Circle" << endl;
  101.     }
  102.  
  103.     Circle (Circle& r) : Shape(r)
  104.     {
  105.     diameter=r.diameter;
  106.     }
  107.   // Constructor
  108.   Circle (int cx, int cy, int dia) : Shape (cx, cy)
  109.     {
  110.       cout << "In Circle Constructer" << endl;
  111.       diameter=dia;
  112.     }
  113.  
  114.     // Destructor
  115.     ~Circle ()
  116.       {
  117.     cout << "In Circle destructor" << endl;
  118.       }
  119.       void draw()
  120.     {
  121.     cout <<"In drawing of Circle"<<endl;
  122.     }
  123.     Circle & operator=(Circle &obj)
  124.     {
  125.     this->setCenter_X(obj.getCenter_X());
  126.     this->setCenter_Y(obj.getCenter_Y());
  127.     this->diameter=obj.diameter;
  128.     return *this;
  129.     }
  130.     // Methods
  131.     void printAllValues();
  132. };
  133.  
Tester code
Expand|Select|Wrap|Line Numbers
  1. #include "shape.h"
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. Rectangle r(10,10,10,10);
  7. r.draw();
  8. Circle aCircle(10,10,10);
  9. aCircle.draw();
  10. cout <<"Rectangle" <<endl;
  11. r.printAllValues();
  12. cout <<endl <<"Circle" <<endl;
  13. aCircle.printAllValues();
  14. cout<< endl <<"Constucting copy of Rectangle" <<endl;
  15. Rectangle r2(r);
  16. r2.printAllValues();
  17. cout << endl <<"Constructing copy of Circle" <<endl;
  18. Circle aNotherCircle(aCircle);
  19. aNotherCircle.printAllValues();
  20.  
  21. cout << endl;
  22. Rectangle rect;
  23. rect=r;
  24. rect.printAllValues()
  25.  
  26. return 0;
  27. }
  28.  
I am so confused why this is not working.
Oct 22 '07 #3
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
First of all the code is not compiling
1)Class Rectangle dosent have a default constructor and it fails there in compilation
2)printAllValue s() dosent have a body for it and gives a linker error.
I made changes locally and after that it compiled and ran successfully without any issues.
I am using g++ with cygwin

Raghuram
Oct 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6328
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
8
2011
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error msg that im getting: "Error executing cl.exe" this is the code that I have, but I know whats causing it, ill just show you the whole thing first though //file: Quadratic
106
6476
by: xtra | last post by:
Hi Folk I have about 1000 procedures in my project. Many, many of them are along the lines of function myfuntion () as boolean on error goto er '- Dim Dbs as dao.database Dim Rst as dao.recordset
5
8921
by: Greg Collins [MVP] | last post by:
I have an ASP.NET page that uses a tag: <asp:Xml id="foo" runat="server" DocumentSource="rss.xml" TransformSource="rss20.xsl" /> This creates a Web page from an XML file that was generated by InfoPath. By default InfoPath inline's their images in base64 encoding. These need to be extracted out to be displayed. I've got my XSL set up to be able to pull out images and manage them separately. According to Microsoft, they need to be decoded...
5
7967
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4, it can open the file. However, when I run Php5 I (now) get this error message: "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" This is new. Last time I messed with this, I merely got:
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.