I've a class of Shape to compute area of a shape among other attributes and functions, and my class Square inherits from it.
In main, I have a vector of shape pointers. After the user inputs their shape and coordinates, I have to store their coordinates into the shape object,then store the object into the vector itself.
I'm not sure how do I store an array into a object,or if it's even possible. Here's what I have tried.
//Global variables vector<Shape> *Shape; void CalculateShapeData() { //Variables declaration string shape; //Store x,y coordinates in array int tempx[100],tempy[100]; cout << "Please enter name of shape : " << endl; cin >> shape; cout << "Please enter special type: " << endl; if (shape == "Rectangle") { } else if (shape == "Square") { for (int i = 0; i < 4;i ++) { cout << "Enter x-coordinate of pt " << i << ":" << endl; //cin >> tempx[i]; cout << "Enter y-coordinate of pt " << i << ":" << endl; //cin >> tempy[i]; //Store coordinates into square object } } I've read an alternative here, but it uses structs. storing input into Arrays C++
I'm not sure if I can do it using arrays instead?
vector<Shape> *Shape;is a bad idea, use different name for the variable