Point p1(100,100);
Point p2(300,200);
Graph_lib::Rectangle r(p1,p2);
And also I have a function that takes a rectangle and returns a Point of that, say, top-left corner of that rectangle. For example:
Point N(Graph_lib::Rectangle R1);
My question is that, first, how to send that Rectangle r(p1,p2) to the Point N(Graph_lib::Rectangle R1) function? And then, how to return a Point from that function?
Helo all i need a programe....topic is filling here i need to add the data of five students their mobile number,address,sec, and deprtmnt....program should be like
s.no name address phone
1.
2.
3.
4.
5.
and starting should be like press 1 to insert data
press 2 to save data
press 3 to find data
press 4 to quit
#include <Simple_window.h>
Point N(Graph_lib::Rectangle r);
//*******************************************************
int main()
{
usingnamespace Graph_lib;
Simple_window win(Point(100,100), 600,400, "Connection_Points");
Point p1(200,100);
Point p2(400,200);
Graph_lib::Rectangle r (p1,p2);
Mark m(N(r),'x');
win.attach(m);
win.wait_for_button();
}
//*******************************************************************
Point n(Graph_lib::Rectangle r)
{
return this_is_a_Point;
}
But I got three errors:
Error 8 error C2248: 'Graph_lib::Shape::Shape' : cannot access private member declared in class 'Graph_lib::Shape' c:\program files\microsoft visual studio 11.0\vc\include\graph.h 212
this_is_a_Point hasn't been declared anywhere, you need to declare and initialize it before you can use it. Helios didn't literally mean return "this_is_a_Point" but rather create a point then return that point.
1) Please don't hijack other people's threads. Start your own thread, if you have a problem you want to solve that's not related to the current thread.
2) This isn't a free homework service. When you start your own thread, please post the code you've already written, and we'll help you figure out any problems you're having with that code.
Mike5424 has already explained the 2nd and 3rd errors you're getting. You've simply copied and pasted some pseudo-code as it were working C++ code. You didn't actually make any effort to understand what it was helios wrote, did you?
As for your first error, you haven't shown us nearly enough code for us to be sure. We'd need to see your definition of Rectangle, and of Shape (which, presumably, is a base class of Rectangle).
My guess, based on limited information, is that you're attempting to access a constructor of Shape that's declared as private. Maybe a default constructor? Or a copy constructor? Maybe it's because your functions N and n take a Rectangle parameter by value, which means that an attempt is being made to call a copy constructor which has been declared as private?
Incidentally, C++ is case-sensitive. n and N are not the same thing.
Edit: I don't understand your final question. What do you mean by "PPP"?
class Shape { // deals with color and style, and holds sequence of lines
public:
void draw() const; // deal with color and draw lines
virtualvoid move(int dx, int dy); // move the shape +=dx and +=dy
void set_color(Color col) { lcolor = col; }
Color color() const { return lcolor; }
void set_style(Line_style sty) { ls = sty; }
Line_style style() const { return ls; }
void set_fill_color(Color col) { fcolor = col; }
Color fill_color() const { return fcolor; }
Point point(int i) const { return points[i]; } // read only access to points
int number_of_points() const { returnint(points.size()); }
virtual ~Shape() { }
protected:
Shape();
virtualvoid draw_lines() const; // draw the appropriate lines
void add(Point p); // add p to points
void set_point(int i,Point p); // points[i]=p;
private:
vector<Point> points; // not used by all shapes
Color lcolor; // color for lines and characters
Line_style ls;
Color fcolor; // fill color
Shape(const Shape&); // prevent copying
Shape& operator=(const Shape&);
};
//------------------------------------------------------------------------------
#include <Simple_window.h>
Point n(Graph_lib::Rectangle r);
Point s(Graph_lib::Rectangle r);
Point e(Graph_lib::Rectangle r);
Point w(Graph_lib::Rectangle r);
Point ne(Graph_lib::Rectangle r);
Point se(Graph_lib::Rectangle r);
Point nw(Graph_lib::Rectangle r);
Point sw(Graph_lib::Rectangle r);
Point center(Graph_lib::Rectangle r);
//*******************************************************
int main()
{
usingnamespace Graph_lib;
Simple_window win(Point(100,100), 600,400, "Connection_Points");
Point p1(200,100);
Point p2(400,200);
Graph_lib::Rectangle r (p1,p2);
Mark m(n(r),'x');
win.attach(m);
win.wait_for_button();
}
//*******************************************************************
Point n(Graph_lib::Rectangle r)
{
return r.point(0);
}
//*************************************************
Point s(Graph_lib::Rectangle r);
//*************************************************
Point e(Graph_lib::Rectangle r);
//*************************************************
Point w(Graph_lib::Rectangle r);
//*************************************************
Point ne(Graph_lib::Rectangle r);
//*************************************************
Point se(Graph_lib::Rectangle r);
//*************************************************
Point nw(Graph_lib::Rectangle r);
//*************************************************
Point sw(Graph_lib::Rectangle r);
//*************************************************
Point center(Graph_lib::Rectangle r);
And the only error is: Error 8 error C2248: 'Graph_lib::Shape::Shape' : cannot access private member declared in class 'Graph_lib::Shape' c:\program files\microsoft visual studio 11.0\vc\include\graph.h 212
So if you look at line 28 of the definition of Shape, it looks as though my guess was correct in my previous post:
MikeyBoy wrote:
My guess, based on limited information, is that you're attempting to access a constructor of Shape that's declared as private. Maybe a default constructor? Or a copy constructor? Maybe it's because your functions N and n take a Rectangle parameter by value, which means that an attempt is being made to call a copy constructor which has been declared as private?
The copy constructor for Shape is private, which means that all objects which derive from Shape (e.g. Rectangle) are non-copyable.
Since you're attempting to pass a Rectangle into n() by value, the copy constructor for Rectangle is being invoked. This, in turn, attempts to invoke the copy constructor of the base class, Shape. However, that copy constructor is private, so it's illegal.
rectangle.h line 1. You did not declare an access level for the inheiritance.
If no access level is specified for the inheritance, the compiler assumes private for classes declared with keyword class and public for those declared with struct. http://www.cplusplus.com/doc/tutorial/inheritance/
Since Shape is a class, the default access level is private and therefore Rectangle does not have access to Shape's constructor since Shape's constructor is protected.
Since Shape is a class, the default access level is private and therefore Rectangle does not have access to Shape's constructor since Shape's constructor is protected.
Oops, yes, you're right. I didn't spot that.
But even once that's fixed, it's going to be illegal to pass a Rectangle by value into a function, as the copy constructor for Shape is private.
I used r.point(0); in line 32 to point to the top-left corner of the rectangle. I need the height and the width of that rectangle in other functions. How to use the height and width of r in those functions?