views:

39

answers:

1

I have Foo.hpp and Foo.cpp, i'd like to define a virtual function

virtual void setValue(int val){
}

Would the following implementation be correct:

Foo.hpp

#ifndef _FOO
#define _FOO
class Foo{
  public:
    Foo();
    virtual void setValue(int val);
};
#endif

Foo.cpp

Foo::setValue(){

}

I realise it would be easier if i kept it to one file, but this is just a simplification of a more complex structure.

+2  A: 

Your example won't compile, because the function signatures are different between your cpp and hpp, but you have the right idea. If your function is void, there is no need to return, either.

sheepsimulator
Oops the return was a typo, edited it.
Kay