C ++ inference operator overloading?

  • 0
    There is a class:

    using namespace std;
    
    class Stroka
    {
        protected:
            static int iCount;
            char * p_char;
            int  size;
        public:
            Stroka()
            {
                cout << "КОНСТРУКТОР  БЕЗ  ПАРАМЕТРОВ [Базовый]" << endl;
                size = 1;
                p_char = new char[size];
                *p_char = '\0';
            }
    
            Stroka(const char *st)
            {
                cout << "КОНСТРУКТОР  С  ПАРАМЕТРАМИ [Базовый]" << endl;
                size = strlen(st);
                p_char = new char[size];
                strcpy(p_char, st);
            }
    
            Stroka(const char ch)
            {
                cout << "КОНСТРУКТОР  С  ПАРАМЕТРАМИ КОТОРЫЙ ПРИНИМАЕТ СИМВОЛ [Базовый]" << endl;
                size = 2;
                p_char = new char[size];
                p_char[0] =  ch;
                p_char[1] = '\0';
            }
    
            Stroka(const Stroka &st)
            {
                iCount++;
                cout << "КОНСТРУКТОР КОПИРОВАНИЯ [Базовый] ВЫЗЫВАЛСЯ " << iCount << " РАЗ" << endl;
                size = strlen(st.p_char);
                p_char = new char[size];
                strcpy(p_char, st.p_char);
    
            }
    
            Stroka operator=(const Stroka & str)
            {
                cout << "ПЕРЕГРУЗКА ОПЕРАЦИИ = [Базовый]" << endl;
                delete [] p_char;
    
                p_char = new char[str.size];
                size = str.size;
    
                strcpy(p_char, str.p_char);
    
                return * this;
            }
    
            unsigned int Size()
            {
                return size;
            }
    
            ~Stroka()
            {
                cout << "ДЕСТРУКТОР [Базовый]" << endl;
                delete [] p_char;
            }
    
            friend ostream & operator<<(ostream &of ,const Stroka & obj);
    };
    
    ostream & operator<<(ostream &of ,const Stroka & obj)
    {
        of << obj.p_char << endl;
    
        return of;
    }


    I can't understand why, when using cout, it does not display the corresponding line, but only the address. Maybe he’s clever somewhere?
    C++ Gabriel Heath, Sep 17, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!