views:

49

answers:

2

Hi there, what is the syntax for defining virtual functions outside the class body?

class random{

public:
   random(int i = 0);
   virtual ~random(){};
   virtual void print() const;
protected:
   int id;      

};

is it?

virtual void random::print() {


}

?

+4  A: 

Just:

struct foo
{
    virtual void bar(void) const;
};

void foo::bar(void) const
{
}

virtual only goes on the declaration.

GMan
+2  A: 

In your case:

void random::print() const {


}
Tomek