c++ header and implementation code example
Example 1: what is a header in c++
#ifndef MY_CLASS_H
#define MY_CLASS_H
namespace N
{
class my_class
{
public:
void do_something();
};
}
#endif
Example 2: defining class in other file in c++
class ClassOne
{
public:
ClassOne();
int method();
private:
int member;
};
#include "ClassOne.hpp"
ClassOne::ClassOne()
:member(0)
{}
int ClassOne::method()
{
return member++;
}
#include "ClassOne.hpp"
int main(int argc, char* argv[])
{
ClassOne c1;
c1.method();
return 0;
}