2 Replies - 252 Views - Last Post: 18 July 2011 - 01:56 AM Rate Topic: -----

#1 Twigz  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 11-July 11

i' m in need of assistance with this peace of code.

Posted 17 July 2011 - 02:07 PM

Umm, this is a piece of code i took from a tutorial i was following.

//file name = CApp.h

#ifndef _CAPP_H_
    #define _CAPP_H_
#include <SDL.h>

class CApp {

    public:

        CApp();

        int OnExecute();

};

#endif


//filename CApp.cpp
#include "CApp.h"
CApp::CApp() {
}

int CApp::OnExecute() {
    return 0;
}

int main(int argc, char* argv[]) {
    CApp theApp;

    return theApp.OnExecute();
}



My problem is: 1) I can't seem to figure out what OnExecute is for.
2)And i don't understand this: CApp::CApp()

Can someone break the code down a bit for me to understand. Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: i' m in need of assistance with this peace of code.

#2 Cocker081288  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 108
  • Joined: 11-April 09

Re: i' m in need of assistance with this peace of code.

Posted 17 July 2011 - 02:45 PM

The CApp::CApp() this looks to me as its the default constructor for the class.
You can tell the class is attached to this file because of this line of code '#include "CApp.h"' this is called a header file and is commonly used in object orientated methods.
You can create your own constructor instead of using the default constructor by editing the CApp.h header file.

The OnExecute section is a function that is defined in the CApp.h file and being called in the main programme it looks like it is being used to simply return the value 0 which I assume closes the program as when return 0 is in main() it ends the program.

The link provided has more information on constructors.
Link

Has this helped?

This post has been edited by stayscrisp: 18 July 2011 - 01:49 AM
Reason for edit:: No need to quote the post above :)

Was This Post Helpful? 1
  • +
  • -

#3 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

Re: i' m in need of assistance with this peace of code.

Posted 18 July 2011 - 01:56 AM

The author of the tutorial is attempting to break down the code into nicely manageable sections.

To full understand what's going on in this and future tutorials of this nature then you will need to learn some more C++ and some OOP concepts. There are tons of books and tutorials on the subject which will help you a great deal.

I really recommend that you give up on those tutorials for now and learn some basic C++ because you are just going to get more and more confused as things go on. Trust me :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1