G
G
Grigory Dikiy2015-04-13 18:51:35
OOP
Grigory Dikiy, 2015-04-13 18:51:35

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();
}

Overload code.
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;
};

The overload itself is implemented as a friend function, and as you know, they cannot be virtual, which does not allow them to be inherited.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2015-04-13
@frilix

dynamic_cast, static_cast, reinterpret_cast

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question