URGENT Help needed on basic C++

Hi, I have a base class called ' Shape ' and 3 sub classes namely 'Square' , 'Rectangle' , 'Cross'. I have problem creating my shapes object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Shape *arrayofshape[size];

if (shape == "Square")

	{

	  

	vertices = 4;

	for (int i = 0; i < vertices; i++){

 

            Point ordinates[i];

 

            cout << "Please enter x-ordinate of pt. " << (i+1) << ":";

            cin >> ordinates[i].x;

 

            cout << "Please enter y-ordinate of pt. " << (i+1) << ":";

            cin >> ordinates[i].y;

 	

          Square square(shape, containsWarpSpace, vertices, ordinates[i]);
          arrayofShapes[size] = &square;
          size++;



Above, shows that my main.cpp is trying to create and storing shape into an array. (But i have an error namely when i'm trying to do so.)
/undefined reference to `Square::Square(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, int, Point)'

I will show more on my .h and .cpp here.
1
2
3
4
5
6
7
8
9
10
11
class ShapeTwoD
{

	protected:
	string name;
	bool containsWarpSpace;
	double area;
	
	public:
	ShapeTwoD();			//Default Constructor
	ShapeTwoD(string, bool);	//takes in string name and bool containsWarpSpace 



1
2
3
4
5
Square::Square(string ShapeName, bool warpspace, int vertices, Point ordinates[]):ShapeTwoD(ShapeName, warpspace)
{
	vert = vertices
	ord[] = ordinates[]
}



I'm new to c++ thus i really need some help here.

Lastly, where i get my Point ord[] from is i created a Point.h (I do not know where to put this at thus im just trying my luck)

1
2
3
4
5
6
7
struct Point {

    int x;

    int y;

};



Would appreciate if i can get help in order for me to solve this and store my shape. Thanks
That Shape stuff is a typical teaching example, but need more details to help you.

Can you post the definitions of Shape, Square, Rectangle and Cross.
I have only started on Square which only shows.

1
2
3
4
5
6
7
8
class Square:public ShapeTwoD{

	private:
	Point ordinate[];

	public:
	Square();
 	Square(string,bool,int,Point);


1
2
3
4
5
6
Square::Square(string ShapeName, bool warpspace, int vertices, Point ordinates[]):ShapeTwoD(ShapeName, warpspace)
{
	vert = vertices
	ord[] = ordinates[]
}


I am trying to store the shape first before moving on to compute their Area.
The point is, you're expected to create a number of shapes (Square ...) that derive from an abstract base class (interface), Shape.

Something (a factory) creates the actual shapes and stores them in that array. You then do things with each element of the array, but the only methods you can call are the methods on your interface class, Shape.

So, Shape will have a method, getName(), which is implemented by all derived classes. For example, the name of a Square is "square".

It's an excersise in Object Oriented Design and Programming.
Hi, i do have getName() in my shape. All i need to know now is how could i create a square as the above is the codes i've done so far.
Topic archived. No new replies allowed.