QList: Append a custom class.



  • Hi,
    I'm new in c++ and qt and I'm struggling with QList and copy-constructor. Compiling results in the following erros:

    error: undefined reference to `MachineSet::operator=(MachineSet const&)'

    within the header file

    class Production
        {
        public:
            Production()
            {
            }
            Production(const Production& production)
            {
                mMachineSet = production.mMachineSet;
            }
            Production &operator = (const Production &other);
    
            MachineSet mMachineSet;
            MaterialSet mMaterialSet;
            ToolSet mToolSet;
            CutterSet mCutterSet;
            GeometrySet mGeometrySet;
        };
    

    The definition of MachineSet is as follows:

    class MachineSet
    {
    public:
        MachineSet(const QString &fileName);
        MachineSet(const MachineSet& machineSet);   // Copy-Konstruktor
        MachineSet();
        MachineSet *operator = (const MachineSet &other);
        ~MachineSet();
    
        enum class MYERROR
        {
            noError,
            couldNotOpenFile,
            dataListIsEmpty,
            xmlStreamReaderError,
            qFileError
        };
    
        class Machine
        {
        public:
           Machine()
           {
               mCompany = "";
               mProductFamiliy = "";
               mProductName = "";
               mProductShortDescription = "";
               mProductDetailedDescription = "";
               mIp4Address = "";
               mUsername = "";
               mPassword = "";
               mLocation = "";
               mMaxWidth = 0.0;
               mMaxLength = 0.0;
               mMaxHight = 0.0;
           }
           QString mCompany;
           QString mProductFamiliy;
           QString mProductName;
           QString mProductShortDescription;
           QString mProductDetailedDescription;
           QString mIp4Address;
           QString mUsername;
           QString mPassword;
           QString mLocation;
           QString mFirstName;
           QString mLastName;
           QString mStreet;
           QString mHouseNumber;
           QString mZipCode;
           QString mCity;
           double mMaxWidth;
           double mMaxLength;
           double mMaxHight;
    
           Machine(const Machine& machine)       // copy-constructor
           {
               mCompany = machine.mCompany;
               mProductFamiliy = machine.mProductFamiliy;
               mProductName = machine.mProductName;
               mProductShortDescription = machine.mProductShortDescription;
               mProductDetailedDescription = machine.mProductDetailedDescription;
               mIp4Address = machine.mIp4Address;
               mUsername = machine.mUsername;
               mPassword = machine.mPassword;
               mLocation = machine.mLocation;
               mFirstName = machine.mFirstName;
               mLastName = machine.mLastName;
               mStreet = machine.mStreet;
               mHouseNumber = machine.mHouseNumber;
               mZipCode = machine.mZipCode;
               mCity = machine.mCity;
               mMaxWidth = machine.mMaxWidth;
               mMaxLength = machine.mMaxLength;
               mMaxHight = machine.mMaxHight;
           }
    
           Machine *operator = (const Machine &other);
        };
    
        QList<Machine> mMachineSetList;
        QFile *p_mXmlFile;
    
        QXmlStreamReader mXmlStreamRead;
        QXmlStreamWriter mXmlStreamWrite;
    
        MYERROR readSetFromXmlFile();
        MYERROR readMachineFromXmlFile(Machine *p_machine);
    
        MYERROR writeSetToXmlFile();
        MYERROR writeMachineToXmlFile(Machine *p_machine);
    
    private:
        QString mFilename;
    
    };
    

    Any idea? Thank you
    Jakob



  • Production &operator = (const Production &other);

    I suspect the issue with the signature. Try changing like the following.

    Production operator = (const Production &other)



  • Thank you for your help. The problem was here:

    MachineSet &operator = (const MachineSet &other);

    changing to

    MachineSet operator = (const MachineSet &other);

    works.

    Thank you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.