How can I use constructor for assignment?

HI!
I couldn't say what I wanted in the title so maybe the title is a little confusing and non-related.
sorry for that!

I have a class "Point" and a class "Rectangle".
I have overloaded [] for Rectangle so that :
1
2
3
4
5
Rectangle tmp ;
//tmp [1] is the top left corner of Rectangle.
//tmp [2] is the top right corner of Rectangle.
//tmp [3] is the bottom left corner of Rectangle.
//tmp [4] is the bottom right corner of Rectangle. 


And every corner of rectangle is a point and I declared Rectangle class like this :
class Rectangle : public Point

Now what I want is that when I write :
1
2
3
Point p ;
Rectangle tmp ;
tmp [2] = p (4 , 5) ;

Then it assigns the point p to the top right corner of Rectangle.
What I did for Point is :
1
2
3
4
5
Point :: Point (int a , int b)
{
    x = a ;
    y = b ;
}


but there is an error :
no match for call to 'Point (int , int)'


I don't know what should I do?
And this is the implantation of classes Point and Rectangle :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Point
{
public :
    void operator = (Point) ;
    bool operator == (Point) ;
    Point (int , int) ;
    Point () {} ;
    void setx () ;
    void sety () ;
    int getx () ;
    int gety () ;
    void showpoint () ;
protected :
    int x , y ;
    friend class Rectangle ;
} ;

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Point.h"

class Rectangle : public Point
{
public :
    Point operator [] (int) ;
    void operator << (Rectangle) ;
    int area () ;
    void operator >> (Point) ;
    void show () ;
private :
    Point p1 , p2 , p3 , p4 ;
} ;


THNX!
If you need any extra information let me know and thanks in advanced for answering.
Last edited on
Why your Rectangle IS-A Point?

tmp [2] = p (4 , 5) ;
This is not calling constructor, because p is an object.
It attempts/could to call a member function Point Point::operator() (int, int) const of object p.

But do not worry, for it will fail anyway, because of
Point Rectangle::operator [] (int)
A nameless copy constructed from Rectangle::p2 is not useful here.
Last edited on
Topic archived. No new replies allowed.