Answer the question
In order to leave comments, you need to log in
How to call the correct constructor?
Hello!
Actually, the task was to write several types of constructors
. I wrote it, but now how to implement it in such a way that by selecting an item in the menu, let's say the copy constructor is transferred to this particular constructor? All constructors are described in 1 class (this is how I try to do it)
do
{
system("cls");
menu_next();
cin >> triger;
switch (triger)
{
case 1:
{
WorkWithArray obj1;
_getch();
break;
}
case 2:
{
WorkWithArray obj2(WorkWithArray obj1);
_getch();
break;
}
case 3:
{
WorkWithArray obj3;
WorkWithArray obj4(obj3.setSecondArraySize(), obj3.setFirstArraySize());
_getch();
break;
}
/*case 4:
{
WorkWithArray obj5(NULL, NULL);
}*/
case 5:
{
WorkWithArray obj6(NULL, NULL);
break;
}
}
} while (triger != 123);
WorkWithArray()
{
firstArray = nullptr;
SecondArray = nullptr;
firstArraySize=0;
SecondArraySize=0;
min =0;
//simpleConstructer
firstArraySize = setFirstArraySize(); //конструктор инициализации
SecondArraySize = setSecondArraySize(); //конструктор инициализации
firstArray = CreateFirstdMemory(firstArraySize);
SecondArray = CreateSecondMemory(SecondArraySize);
min = compare(firstArraySize, SecondArraySize);
LastArray = CreateLastMemory(firstArraySize,SecondArraySize,min,firstArray,SecondArray);
OutputLastArray(LastArray,min);
}
//work with coppy constructur
WorkWithArray(const WorkWithArray &workinArray)
{
int FirstArraySize = workinArray.firstArraySize;
int SecondArraySize = workinArray.SecondArraySize;
firstArray = CreateFirstdMemory(FirstArraySize);
SecondArray =CreateSecondMemory(SecondArraySize);
min = compare(FirstArraySize, SecondArraySize);
LastArray = CreateLastMemory(FirstArraySize, SecondArraySize, min, firstArray, SecondArray);
OutputLastArray(LastArray, min);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question