-1

Getting error, but not understanding the behaviour:

class A {
    virtual void foo() = 0;
    virtual int bar();
}

Here I am getting error "only non-static member functions may be virtual" I gave implementation for bar();.

0

2 Answers 2

3

The error message is missleading, the problem is that bar has no return type, which is illegal.

7
  • SOrry for typo, return value is int
    – Sijith
    Nov 1, 2012 at 14:56
  • @Sijith So the code you have is virtual int bar();?
    – David G
    Nov 1, 2012 at 14:56
  • @Sijith a typo is virutal instead of virtual.... Nov 1, 2012 at 14:57
  • Yes David, its an interface class. All other function in my class is virtual
    – Sijith
    Nov 1, 2012 at 14:57
  • @Sijith post the code on ideone.com see if you get the error there. Nov 1, 2012 at 14:58
0

Static members are shared (statically) among all instances of the class as opposed to virtual functions which expose dynamic behavior and allow different execution according to the object type. So it makes no sense to have static virtual functions.

Besides that the code you presented has no static functions so please post the full version here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.