Operatoren überladen



  • Warum geht des Programm net zu kompilieren???

    //bsp10064.h
    
    #ifndef _AB_
    #define _AB_
    
    class A {
        friend void uebernehme(A &obj, char *t);
        public:
            A(char *t);
            void zeigeinhalt();
        private:
            char text[51];
    };
    
    class B {
        friend void uebernehme(B &obj, int z);
        public:
            B(int x, int y);
            void zeigeinhalt();
        private:
            int _x,_y;
        };
    #endif
    
    #include <iostream>
    #include <cstring>
    #include "AB.h"
    using namespace std;
    
    A::A(char *t) {
        strncpy (text, t, 50);
    }
    
    void A::zeigeinhalt() {
        cout << "\nInhalt von A. " << text;
    }
    
    B::B (int x, int y) {
        _x=x;
        _y=y;
    }
    
    void B::zeigeinhalt() {
        cout << "\nInhalt von B: _x=" << _x
             << " _y=" << _y;
    }
    
    void uebernehme (B &obj, int z) {
        obj._x+=z;
        obj._y+=z;
    }
    
    void uebernehme (A &obj, char *t) {
        strncat (obj.text, t, 50-strlen(obj.text));
    }
    
    #include <iostream>
    #include "AB.h"
    using namespace std;
    
    int main() {
        A a1("Text zum Testen");
        B b1(10, 20);
        a1.zeigeinhalt();
        b1.zeigeinhalt();
        uebernehme(a1, "mit Zusatz");
        uebernehme(b1, 5);
        a1.zeigeinhalt();
        b1.zeigeinhalt();
        fflush(stdin);
        getchar();
        return 0;
    }
    


  • sorry für posting ich depp hatte es nicht als Projekt verpackt


Anmelden zum Antworten