0

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

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Stinomus
0

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);
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.