Как прописать инициализацию объекта класса, у которого атрибут является объектом другого класса?
Необходимо прописать инициализацию векторного пространства.
Для начала я прописал класс точка таким образом:
class point{
private:
double x;
double y;
double z;
public:
point(double value_x, double value_y, double value_z){
x = value_x;
y = value_y;
z = value_z;
}
double get_point_x() const{
return x;
}
double get_point_y() const{
return y;
}
double get_point_z() const{
return z;
}
void get_coord() const{
cout << x << ' ' << y << ' ' << z;
}
void add(point point1, point point2){
x = point1.x + point2.x;
y = point1.y + point2.y;
z = point1.z + point2.z;
}
void sub(point point1, point point2){
x = point1.x - point2.x;
y = point1.y - point2.y;
z = point1.z - point2.z;
}
void mul(point point, double c){
x = point.x * c;
y = point.y * c;
z = point.z * c;
}
void div(point point, double c){
if (c == 0) exit(0);
x = point.x / c;
y = point.y / c;
z = point.z / c;
}
static double distance(point point1, point point2){
return sqrt(pow(point2.x - point1.x, 2) + pow(point2.y - point1.y, 2) + pow(point2.z - point1.z, 2));
}
};
Далее я прописал класс вектор:
class vector{
private:
double x;
double y;
double z;
public:
vector(point point){
x = point.get_point_x();
y = point.get_point_y();
z = point.get_point_z();
}
void get_coord() const{
cout << x << ' ' << y << ' ' << z;
}
double get_length(vector vec){
return sqrt(pow(vec.x, 2) + pow(vec.y, 2) + pow(vec.z, 2));
}
double get_vector_x() const{
return x;
}
double get_vector_y() const{
return y;
}
double get_vector_z() const{
return z;
}
void add(vector vec1, vector vec2){
x = vec1.x + vec2.x;
y = vec1.y + vec2.y;
z = vec1.z + vec2.z;
}
void sub(vector vec1, vector vec2){
x = vec1.x - vec2.x;
y = vec1.y - vec2.y;
z = vec1.z - vec2.z;
}
void div(vector vec, double c){
if (c == 0) exit(0);
x = vec.x / c;
y = vec.y / c;
z = vec.z / c;
}
void num_mul(vector vec, double c){
x = vec.x * c;
y = vec.y * c;
z = vec.z * c;
}
static double scal_mul(vector vec1, vector vec2){
return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z;
}
void vec_mul(vector vec1, vector vec2){
x = vec1.y * vec2.z - vec1.z * vec2.y;
y = vec1.x * vec2.z - vec1.z * vec2.x;
z = vec1.x * vec2.y - vec1.y * vec2.x;
}
};
Однако у меня возникли неприятность при написании векторного пространства:
class vector_space {
private:
point o;
vector v1;
vector v2;
vector v3;
public:
vector_space(point point, vector vec1, vector vec2, vector vec3){
o = point;
v1 = vec1;
v2 = vec2;
v3 = vec3;
}
};
Такая инициализация не работает и я не знаю, что дальше делать.