completely a newbie question - about cpp/hpp files
As I started to use C++ this tuesday, I did not know anything about it. For now, I tought I should do all the code like:
Code:
// file: Foo.cpp
#ifndef INCLUDED_FOO
#define INCLUDED_FOO
#include <string>
using namespace std;
class Foo
{
private:
string s;
public:
virtual ~Foo() {}
virtual void print()
{
cout<<"foo";
}
};
#endif
--------
// file: Bar.cpp
#ifndef INCLUDED_BAR
#define INCLUDED_BAR
#include <string>
using namespace std;
#include "Foo.cpp"
class Bar : public Foo
{
private:
string g;
public:
virtual ~Bar() {}
void print()
{
cout<<"bar";
}
};
#endif
ok, I realized that I have to split the code into hpp and cpp files.
Well I tried the following, but the gcc compiler prompts about
virtual outside class declaration...
Code:
// foo.hpp
#ifndef INCLUDED_FOO_HPP
#define INCLUDED_FOO_HPP
class Foo
{
private:
string s;
public:
virtual ~Foo() {}
virtual void print();
};
#endif
-----
// foo.cpp
#include <string>
using namespace std;
#include "Foo.hpp"
virtual Employee::~Employee() {}
virtual void Employee::print()
{
cout<<"foo";
}
What I`m missing here?