user592748
user592748

Reputation: 1234

Override keyword throwing an error while compile

I have base class

template<typename T>
Class Base {
  Base();

public:
  virtual void myfunc()=0; 
}

I have derived class

template<typename T>
Class Derived: public Base<T> {
  Derived():Base() {
  }

public:
  void myfunc() override; 
}

When I compile g++ -std=c++0x, I get the error with the overriding function highlighted, error: expected ‘;’ at end of member declaration error: ‘override’ does not name a type

g++ version is 4.6.

Upvotes: 7

Views: 15415

Answers (2)

David G
David G

Reputation: 96845

g++ 4.6.3 doesn't support the override feature of C++11. When you take away the syntatical errors, this code compiles fine in 4.7.2 and Clang.

Moreover, I think this is what you meant your code to be:

template <typename T>
class Base {
   Base();

   public:
      virtual void myfunc() = 0; 
};

template <typename T>
class Derived : public Base<T> {
   Derived() : Base<T>() {}

   public:
      void myfunc() override;
};

Upvotes: 8

haitaka
haitaka

Reputation: 1856

override keyword is not supported by GCC 4.6. If you want to override myfunc, just delete override keyword or upgrade GCC to 4.7 version. (Ref: https://blogs.oracle.com/pcarlini/entry/c_11_tidbits_explicit_overrides)

Upvotes: 9

Related Questions