Composition > can't we use set function of parent class

From parent class, I mean the class whose obj has been made in the class after that.
As I'm trying to do. Is there any solution, or I'll have to set all the members again?
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;

class a{
	int x,y;
public:
	a(int u = 0, int v = 0);
	void setXY(int,int);
	int getX();
	int getY();
};

a::a(int u, int v){
	x = u, y = v;
}
void a::setXY(int u, int v){
	x = u, y = v;
}
int a::getX(){
	return x;
}
int a::getY(){
	return y;
}

class b{
	int z;
	a obj;
public:
	b(int = 0, int = 0, int = 0);
	void setXYZ(int,int,int);
	int getZ();
};

b::b(int u, int v, int w): obj(u,v){
	/////////////
	z = w;
}
void b::setXYZ(int a, int b, int c){
	setXY(a,b);///,/////
	z = c;
}
void b::getZ(){
	return z;
}


int main(){
///
///
///
}
Last edited on
There is no inheritance here, so there is no parent class.

1
2
3
4
void b::setXYZ(int a, int b, int c){
	obj.setXY(a,b);///,/////
	z = c;
}
Last edited on
Topic archived. No new replies allowed.