так что в основном у меня есть класс System, который построен как серия плоскостей и сфер (которые также являются классами).Плоскости и сферы (элементы) являются подклассами класса Element_CR.
Например, система выглядит следующим образом ->
System system0 = {PlaneElement0, Sphere0, Sphere1, PlaneElement1};
Теперь каждая плоскость и сфера получили параметр высоты.Сферы и Плоскости получили собственные функции «set» и «get» для высот и других параметров.
Sphere0.set(2.0); // sets the height to 2.0
Sphere0.get(); // returns the height value
Моя цель - иметь возможность взять 2 Системы A и B (с одной и той же Плоскостью / Сферой).серии) и поменяйте местами их параметры высоты.
System systemA = {Sphere0, Sphere1,PlaneElement0};
System systemB = {Sphere2, Sphere3,PlaneElement1};
Итак, давайте вернемся к моему упрощенному коду
class Element_CR {
public:
Element_CR() {};
~Element_CR() {};
virtual Element_CR* crossover_ptr(Element_CR* A, Element_CR* B)=0;
}
//now the first subclass PlanElement
class PlanElement : public Element_CR
{
public:
PlanElement() {};
PlanElement(double semiHeight) :
mSemiHeightPlanParam(semiHeight)
{
buildPlanGeometry_LLT();
};
~PlanElement() {};
//function for setting the height
void set(double height);
//function that returns the height
double get();
//now the virtual override function
virtual Element_CR* crossover_ptr(Element_CR* planA, Element_CR* planB) override;
//as I mentioned before the goal is to swap the values between the plane A and plane B Heights.
// So first just getting plane A to have the plane B Height would be fine.
//now the definition of the crossover_ptr function for the Plane element
Element_CR* PlanElement::crossover_ptr(Element_CR* planA, Element_CR* planB) {
PlanElement crossPlan = planA;
//so here i get errors, since when i type "planB."
//it doesnt show me the "set" function that has been defined in the PlaneElement class
//it says basically "Element_CR* A expression must have class type"
crossPlan.set(planB.get());
return &crossPlan
}
Теперь то же самое следует сделать с элементом Sphere (вторым подклассом Element_CR), но это можно решить аналогичноЭлемент Плоскости.Класс Sphere Element получает то же «виртуальное переопределение Element_CR * crossover_ptr (Element_CR *phereA, Element_CR *phereB);»
Итак, в конце я хочу иметь возможность зациклить две Системы (построенные из Элементов) и поменять местами высоты Элементов (двух систем).
Это, вероятно, основнойпроблема, но я новичок в c ++ (вероятно, как большинство людей, которые задают вопросы).Буду очень благодарен за любые предложения и помощь, Лепина