override in method definitions doesn't compile!!

Hi,

I have the following code:

class Z {
public:
virtual void doit() const;
};

class ZZ : public Z {
public:
void doit() const override;
};

void Z::doit() const {

}

void ZZ::doit() const override {

}


I would have assumed that the definition of ZZ:doit() should include the modifiers (const and override) but that gives me an error:
"Expected function body after function declarator" and it points to the start of the override keyword in the definition. The declaration in the class is fine..

Seems confusing ... Is this a compiler problem? (using Xcode 7.2 in MAC OSX)

Thanks
Juan
You should only use the override keyword while declaring the function in the class definition.

1
2
3
void ZZ::doit() const override {

}
Last edited on
thanks!!
Topic archived. No new replies allowed.