473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Need help with this error

9
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 1313
gpraghuram
1,275 Expert 1GB
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
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 Expert 1GB
Hi,
First of all the code is not compiling
1)Class Rectangle dosent have a default constructor and it fails there in compilation
2)printAllValues() 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
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,...
8
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...
106
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...
5
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...
5
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.