Answer the question
In order to leave comments, you need to log in
Binary overload inheritance?
Hello, I need to cast a parent class to a child class in order to use the overloaded child class operator. The overloaded operator itself is defined as a friend function because it takes two values.
pointClass[0] - a pointer that is initialized as a base class
void SplitString(int choice)
{
char string[100];
system("clear");
cout << "Введите значение второго операнда" << endl;
cin >> string;
Str_Indef strIndef(string);
strIndef = strIndef + (Str_Indef)*pointClass[0]; // Так я привожу и не работает
strIndef.Print();
Pause();
}
const Str_Indef operator +(const Str_Indef& right, const Str_Indef& left)
{
std::cout << "ПЕРЕГРУЗКА ОПЕРАЦИИ + [Строка-Идетификатор]" << std::endl;
char *pointerChar = new char[right.size + left.size-1];
strcpy(pointerChar, left.p_char);
strcat(pointerChar, right.p_char);
Str_Indef returnString;
returnString.p_char = pointerChar;
returnString.size = strlen(pointerChar);
return returnString;
};
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