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?
Thanks

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

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


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

bool MyApp::OnInit()
{

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

IMPLEMENT_APP(MyApp);

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.