Constructor containing variables of another class in C++

I'm trying to understand how classes work and I have an issue I don't know how to fix.

Here's the code (please, point out any mistakes I have, I'll appreciate it):

#include <iostream>

class Point{
    public:
        Point(double i_x, double i_y) : x(i_x), y(i_y){}

        void print(){
            std::cout << "("<< x <<","<< y <<")"<< std::endl;
        }

        double get_x(){ return x;}
        double get_y(){ return y;}
        void change_x(double i_x){ x = i_x;}
        void change_y(double i_y){ y = i_y;}
    private:
        double x;
        double y;        
};

class Triangle{
    Triangle(Point i_a, Point i_b, Point i_c) { }
    private:
        Point a;
        Point b;
        Point c;
};

int main(void){
    return 0;
}

The point of the assignment is to create a class which represents a point on a 2D plane, and then create a class Triangle that will contain three objects of Point class.

The problem I'm having is in the Triangle class constructor. I've read documentation and other answers on this topic, and still can't understand what I have to put to make it work.

The error is:

no matching function for call to «Point::Point()»

I've tried changing line 5 to:

Point::Point(double i_x, double i_y) : x(i_x), y(i_y){}

and even to:

Point::Point(double i_x, double i_y) { x = i_x; y = i_y; }

but nothing seems to work...

Upvotes: -1

Views: 62

Answers (0)

Related Questions