Fehler bei der Compilerung bei der Move-Zuweisung



  • Hallo,
    ich versuche eine Dummy-Programm bzgl. der Move-Semantik zu compilieren. Leider funzt es nicht. Kann mir jemand helfen?

    ... Code ...

    #include <iostream>
    #include <cstring>
    #include <string>
    class HeapData
    {

    private:
    char *data;

    public:
    HeapData()
    {
    data=new char[27];

    }
    
    virtual ~HeapData()
    {
        delete[] data;
        data=NULL;
        
    }
    
    
    HeapData& operator=(const HeapData &other)
    {
        
        delete[] data;
        data=NULL;
        data=new char[27];
        memcpy(data, other.data, sizeof(char)*27);
        return *this;
    }
    
    
    HeapData(const HeapData &h)
    {
        delete[] data;
        memcpy(data, h.data, sizeof(char)*27);
    }
    
    
    HeapData(HeapData&& temp)
    {
        data=temp.data;
        temp.data=NULL;//null;
    }
    
    HeapData& operator=(Heapdata&& other)
    {
        if (this!=&other)
        {   
            delete[] data;
            data=other.data;
            other.data=NULL;
            
        }
        return *this;
    }
    

    };

    int main()
    {
    return 0;
    }
    ...

    Fehlermeldung:
    ... Code ...
    /bin/sh -c '/usr/bin/make -j4 -e -f Makefile'
    ----------Building project:[ kkkk - Debug ]----------
    make[1]: Entering directory '/home/xx/test/kkkk'
    /usr/bin/g++ -c "/home/xx/test/kkkk/test.cpp" -g -O0 -std=c++14 -std=c++11 -Wall -o ./Debug/test.cpp.o -I. -I.
    /home/xx/test/kkkk/test.cpp:49:25: error: declaration of 'operator=' as non-function
    HeapData& operator=(Heapdata&& other)
    ^
    /home/xx/test/kkkk/test.cpp:49:23: error: expected ';' at end of member declaration
    HeapData& operator=(Heapdata&& other)
    ^
    /home/xx/test/kkkk/test.cpp:49:33: error: expected ')' before '&&' token
    HeapData& operator=(Heapdata&& other)
    ^
    /home/xx/test/kkkk/test.cpp:83:1: error: expected '}' at end of input
    }
    ^
    /home/xx/test/kkkk/test.cpp:47:5: error: expected unqualified-id at end of input
    }
    ^
    kkkk.mk:95: recipe for target 'Debug/test.cpp.o' failed
    make[1]: *** [Debug/test.cpp.o] Error 1
    make[1]: Leaving directory '/home/xx/test/kkkk'
    Makefile:4: recipe for target 'All' failed
    make: *** [All] Error 2
    ====6 errors, 0 warnings====

    ...



  • Du hast dich bei dem Parametertyp verschrieben, die Klasse heißt HeapData, nicht Heapdata.



  • So ein bescheuerter Fehler!!!
    Vielen Dank!!


Anmelden zum Antworten