Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a rectangle class with a friend point class. I am using cartesian coordinates, so I will have four points in the rectangle class. The points are defined in the point class. When defining the rectangle constructor in the source file, I get the error(marked in comment):

Rectangle has no member Rectangle

header:

using namespace std;

class Rectangle
{
public:
    Rectangle(Point, Point, Point, Point);
    friend class Point;
    ~Rectangle();
private:
    Point a;
    Point b;
    Point c;
    Point d;
};

class Point
{
public:
    Point(int, int);
private:
    int x;
    int y;
};

source:

Rectangle::Rectangle(Point v1, Point v2, Point v3, Point v4)    //error here
{

}

Point::Point(int value1, int value2)
{
    if (x <= 20 && y <= 20){
        x = value1;
        y = value2;
    }
    else{
        throw invalid_argument("");
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
263 views
Welcome To Ask or Share your Answers For Others

1 Answer

Remove the asterisks in your constructor declaration.

Either forward declare Point, or declare Point before Rectangle.

You also really shouldn't use "using namespace" inside of a header file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...