test has exited due to signal 10 (SIGBUS).
This is the circle class -
-
#include <iostream.h>
-
-
-
class Shape
-
{
-
private:
-
int x_Center, y_Center;
-
-
public:
-
Shape()
-
{
-
cout <<"In defualt constructer";
-
}
-
Shape(Shape& sh)
-
{
-
x_Center=sh.x_Center;
-
y_Center=sh.y_Center;
-
}
-
// Constructors
-
Shape(int cx, int cy)
-
{
-
x_Center=cx;
-
y_Center=cy;
-
}
-
-
// Member functions
-
int getCenter_X();
-
int getCenter_Y();
-
virtual void draw()=0;
-
};
-
-
class Rectangle : public Shape
-
{
-
private:
-
int length,width;
-
-
public:
-
-
// Default constructor
-
Rectangle (Rectangle& r) : Shape(r)
-
{
-
length=r.length;
-
width=r.width;
-
}
-
-
// Constructor
-
Rectangle (int cx, int cy,int l,int w) : Shape(cx, cy)
-
{
-
length=l;
-
width=w;
-
cout << "In Rectangle constructor" << endl;
-
}
-
-
-
-
// Destructor
-
~Rectangle ()
-
{
-
cout << "In Rectangle destructor" << endl;
-
}
-
-
void draw()
-
{
-
cout <<"In drawing of Rectangle"<<endl;
-
}
-
-
Rectangle & operator=(const Rectangle &obj)
-
{
-
int cx=this->getCenter_X();
-
int cy=this->getCenter_Y();
-
int length=this->length;
-
int width=this->width;
-
Rectangle newRect(cx,cy,length,width);
-
-
return newRect;
-
}
-
// Methodds
-
void printAllValues();
-
};
-
-
class Circle : public Shape
-
{
-
private:
-
int diameter;
-
-
public:
-
-
// Default Constructor
-
Circle ()
-
{
-
cout << "In the default constructor of Circle" << endl;
-
}
-
-
Circle (Circle& r) : Shape(r)
-
{
-
diameter=r.diameter;
-
}
-
// Constructor
-
Circle (int cx, int cy, int dia) : Shape (cx, cy)
-
{
-
cout << "In Circle Constructer" << endl;
-
diameter=dia;
-
}
-
-
// Destructor
-
~Circle ()
-
{
-
cout << "In Circle destructor" << endl;
-
}
-
void draw()
-
{
-
cout <<"In drawing of Circle"<<endl;
-
}
-
Circle & operator=(const Circle &obj)
-
{
-
int cx=this->getCenter_X();
-
int cy=this->getCenter_Y();
-
int diameter=this->diameter;
-
Circle newCircle(cx,cy,diameter);
-
-
return newCircle;
-
}
-
// Methods
-
void printAllValues();
-
};
-
This is the tester -
#include "shape.h"
-
#include <iostream>
-
-
int main()
-
{
-
Rectangle r(10,10,10,10);
-
r.draw();
-
Circle aCircle(10,10,10);
-
aCircle.draw();
-
cout <<"Rectangle" <<endl;
-
r.printAllValues();
-
cout <<endl <<"Circle" <<endl;
-
aCircle.printAllValues();
-
cout<< endl <<"Constucting copy of Rectangle" <<endl;
-
Rectangle r2(r);
-
r2.printAllValues();
-
cout << endl <<"Constructing copy of Circle" <<endl;
-
Circle aNotherCircle(aCircle);
-
aNotherCircle.printAllValues();
-
-
cout << endl;
-
Rectangle rect;
-
rect=r;
-
rect.printAllValues()
-
-
return 0;
-
}
Why is this Error happening and what does it mean?
3 1313
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 -
Rectangle & operator=(const Rectangle &obj)
-
{
-
//fill the this ooj with values from obj and return this lik
-
cx=obj.getCenter_X();
-
//first check for this is = to obj
-
return *this.
-
}
-
2)Same is the case with Circle & operator=(const Circle &obj)
Correct these errors and try to run the code.
Raghuram
Here is the updated code. It still gives a SIGBUS error and I don't know why.
Main code -
-
#include <iostream.h>
-
-
-
class Shape
-
{
-
private:
-
int x_Center, y_Center;
-
-
public:
-
Shape()
-
{
-
cout <<"In defualt constructer";
-
}
-
Shape(Shape& sh)
-
{
-
x_Center=sh.x_Center;
-
y_Center=sh.y_Center;
-
}
-
// Constructors
-
Shape(int cx, int cy)
-
{
-
x_Center=cx;
-
y_Center=cy;
-
}
-
-
// Member functions
-
int getCenter_X();
-
int getCenter_Y();
-
void setCenter_X(int i)
-
{
-
x_Center=i;
-
}
-
void setCenter_Y(int i)
-
{
-
y_Center=i;
-
}
-
virtual void draw()=0;
-
};
-
-
class Rectangle : public Shape
-
{
-
private:
-
int length,width;
-
-
public:
-
-
// Default constructor
-
Rectangle (Rectangle& r) : Shape(r)
-
{
-
length=r.length;
-
width=r.width;
-
}
-
-
// Constructor
-
Rectangle (int cx, int cy,int l,int w) : Shape(cx, cy)
-
{
-
length=l;
-
width=w;
-
cout << "In Rectangle constructor" << endl;
-
}
-
-
-
-
// Destructor
-
~Rectangle ()
-
{
-
cout << "In Rectangle destructor" << endl;
-
}
-
-
void draw()
-
{
-
cout <<"In drawing of Rectangle"<<endl;
-
}
-
-
Rectangle & operator=(Rectangle &obj)
-
{
-
int x=obj.getCenter_X();
-
int y=obj.getCenter_Y();
-
this->setCenter_X(x);
-
this->setCenter_Y(y);
-
this->length=obj.length;
-
this->width=obj.width;
-
return *this;
-
}
-
// Methodds
-
void printAllValues();
-
};
-
-
class Circle : public Shape
-
{
-
private:
-
int diameter;
-
-
public:
-
-
// Default Constructor
-
Circle ()
-
{
-
cout << "In the default constructor of Circle" << endl;
-
}
-
-
Circle (Circle& r) : Shape(r)
-
{
-
diameter=r.diameter;
-
}
-
// Constructor
-
Circle (int cx, int cy, int dia) : Shape (cx, cy)
-
{
-
cout << "In Circle Constructer" << endl;
-
diameter=dia;
-
}
-
-
// Destructor
-
~Circle ()
-
{
-
cout << "In Circle destructor" << endl;
-
}
-
void draw()
-
{
-
cout <<"In drawing of Circle"<<endl;
-
}
-
Circle & operator=(Circle &obj)
-
{
-
this->setCenter_X(obj.getCenter_X());
-
this->setCenter_Y(obj.getCenter_Y());
-
this->diameter=obj.diameter;
-
return *this;
-
}
-
// Methods
-
void printAllValues();
-
};
-
Tester code -
#include "shape.h"
-
#include <iostream>
-
-
int main()
-
{
-
Rectangle r(10,10,10,10);
-
r.draw();
-
Circle aCircle(10,10,10);
-
aCircle.draw();
-
cout <<"Rectangle" <<endl;
-
r.printAllValues();
-
cout <<endl <<"Circle" <<endl;
-
aCircle.printAllValues();
-
cout<< endl <<"Constucting copy of Rectangle" <<endl;
-
Rectangle r2(r);
-
r2.printAllValues();
-
cout << endl <<"Constructing copy of Circle" <<endl;
-
Circle aNotherCircle(aCircle);
-
aNotherCircle.printAllValues();
-
-
cout << endl;
-
Rectangle rect;
-
rect=r;
-
rect.printAllValues()
-
-
return 0;
-
}
-
I am so confused why this is not working.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |