0

Shape.h

class Shape {

private:
string name;

public:
Shape(name);
string getName();
void setName(string);
};

Triangle.h

class Triangle: public Shape {

private:
int x;
int y;

public:
Triangle(name,int[3],int[3]);
int getX();
int getY();
void setX(int);
void setY(int);
};

Triangle.cpp

Triangle::Triangle(string name,int _x[],int_y[]):Shape(name) {
x[] = _x[];
y[] = _y[];

}

int Square::getX() {
return x
}

int Square::getY() {
return y;
}

void Square::setX(int _x) {
x = _x;
}

void Square::setY(int _y) {
y = _y;
}

i need to create triangle that takes in name and 3 points of (x,y). when i try to create an array of triangle on the main Triangle Tri[50]; i got the following errors

Triangle::Triangle(std::string,int*,int*)
candidates expects 3 arguments, 0 provided
Triangle::Triangle(const Triangle&)
candidates expects 1 argument, 0 provided

can pls help me check what is wrong with my constructor?? is it because i am creating an array of objects that store arrays of x and y? so i need to use references and pointers for it?

1 Answer 1

1

When you create

Triangle Tri[50]; 

it will try to call the default constructor to initialize those elements in your Tri array, however, you did not provide such a default constructor and you did not call the constructor with 3 parameters, therefore, compiler complains.

Meanwhile, you seems to try to directly initialize one array with another inside the constructor of Triangle:

Triangle::Triangle(string name,int _x[],int_y[]):Shape(name) {
   x[] = _x[];//^^I don't understand how this will work in practice.
   y[] = _y[];
} 

There is no direct assignment on arrays in C++, though C++ std::array (since C++11) has overloaded operator=, but this is not true for regular array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.