views:

72

answers:

1

I have a function declared in my base class and specified as virtual, I am trying to re-declare it in a derived class but I'm getting a multiple declaration error.

Anyone know if I'm missing something here?

class Field {
    public:
        virtual void display() = 0;
        virtual int edit() = 0;
        virtual bool editable() const = 0;
        virtual void *data() = 0;
        virtual Field *clone() const = 0;
};

class LField : public Field {
        int rowNum;
        int colNum;
        int width;
        char *val;
        bool canEdit;
        int index;
    public:
        virtual void *data() { return val; }
};


class IVField : public LField { 

    void (*ptrFunc)(void *);
    bool (*ptrValid)(int &);
    int *data;

    public:
        void* data() { 
            return data;
        }

};

class DVField : public LField {
    int decimalsToDisplay;
    double *data;
    void (*ptrFunc)(void *);
    bool (*ptrValid)(double&);
    public:

        void* data() { 
            return data;
        }

};
+4  A: 

You have a function named data and a member variable named data in the same class. That's not allowed. Pick a different name for your member variable.

You also appear to be re-declaring many member variables. That's probably not what you want to do. If you want to declare them in the base class and use them in descendants, then they should probably have protected visibility. The default visibility for classes, when you haven't specified any other, is private, which means, for example, that descendants of IVField (such as DVField) cannot access the ptrFunc variable you declared in IVField. The ptrFun variable you declared in DVField has absolutely no relation to the one declared in the parent class. Make the IVField one protected, and then descendants don't need to duplicate the declaration for themselves.

You're also going to have to implement all those other abstract methods before the compiler will allow you to instantiate any of those classes.

Rob Kennedy
Yes this was the problem. Thanks :) Will check mark when the timer is done.
Marcin