Composition

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
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
hey mike
i want to make x object that contains serveal point .
x(point1,point2)\i might be confued about what i try ..
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.
ok still you didnt direct me how to solve it.
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/
thanks alot kesk but i mange to understand what was wrong without using vectors.
tnx mate (:
Topic archived. No new replies allowed.