Composition

Jul 12, 2017 at 4:40pm
im having a diffcult time to understand this copmosition for some reason
be happy if someone can direct me

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
#include<iostream>
using namespace std;

class point{
	int x, y;
public:
	point (int xx, int yy) :x(xx), y(yy) {}

};
class x:public point {
	point* nums;
	int size;
public:
	x(int a,int b):point(a,b){
		

	}


};
int main() {
	point p1(1, 1);
	point p2(2, 2);
	x b(p1, p2);



	system("pause");
	return 0;
}


how do i do when i make new X object like put few point like x(p1,p2)?
open new array ? when i call x object?
Last edited on Jul 12, 2017 at 4:42pm
Jul 12, 2017 at 5:26pm
OK, I'm not understanding your design here. x inherits from point, which means that it is a point. But x also contains what appears to be an array of points. Why?
Last edited on Jul 12, 2017 at 5:26pm
Jul 12, 2017 at 5:35pm
hey mike
i want to make x object that contains serveal point .
x(point1,point2)\i might be confued about what i try ..
Jul 12, 2017 at 5:41pm
Then there's no reason for x to inherit from point. I'm guessing you haven't understood what inheritance is, or when to use it. You probably want to go back to your textbook and reread about inheritance.
Jul 12, 2017 at 5:48pm
ok still you didnt direct me how to solve it.
Jul 12, 2017 at 6:10pm
You want an object that contains several points. A container. C++ Standard Library has container.
For example: http://www.cplusplus.com/reference/vector/vector/vector/

Your thread title is "composition", not "inheritance". While it is good for to reread the inheritance material, you should read about composition too.
For example: http://www.learncpp.com/cpp-tutorial/102-composition/
Jul 12, 2017 at 6:24pm
thanks alot kesk but i mange to understand what was wrong without using vectors.
tnx mate (:
Topic archived. No new replies allowed.