I have simple question.
I have long code in my .cpp file with classes functions etc.
I would like to divide it into separate cpp and .h files. What are rules governing the stuffing? Any good tutorial/example?
Cheers :)

ok, let me clarify with example. I have code like belo and want to split it inot .h and .cpp, what are rules to follow?

#include <wx/wx.h>
class MyApp : public wxApp
    virtual bool OnInit();

class MyFrame : public wxFrame
        MyFrame(const wxString& title);

MyFrame::MyFrame(const wxString& title)
        : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))

bool MyApp::OnInit()

    MyFrame *newFrame = new MyFrame(wxT("Hello Mary!"));
    //wxPanel *myPanel = new wxPanel(this, wxID_ANY); ====== to be attended
    return true;


class MyApp ... goes in MyApp.h
Along with any necessary includes to make MyApp.h a standalone include (that is, anyone who includes it doesn't have to go fishing to find pre-requisite includes)

bool MyApp::OnInit ... goes in MyApp.cpp
This includes MyApp.h

Ditto for the others.

In your example, MyApp.cpp would also include MyFrame.h

Each class has a .h file for the interface, and a .cpp for the implementation.

Which is about what the link posted above said.

In general all of your implementation code aside from inline and template functions goes in the .cpp (the implementation file).

This article has been dead for over six months. Start a new discussion instead.