Thread: Slitting up code

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    2

    Slitting up code

    This should be a simple question, as I am pretty new to C++

    What I need is to be able to tidy up my code and access parts from other points, to me these are functions, an example of what I imagine such a thing would be like is.

    I've put in samples of the code I am using, its using the irrlicht engine for it.

    Code:
    //The code snippet
    function banana();
    {
    //code
    scene::ISceneManager* smgr = device->getSceneManager();
    }
    
    int main();
    {
       banana();
       scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("room1.dmf");
       scene::ISceneNode* q3node = 0;
    }

    cheers.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I'm not sure what exactly you are asking about. Maybe you want a function prototype for banana() in a header file, then the function definition in a source file. In your main source file you would #include the header, and you would compile and linnk both source files in your project/makefile/command line.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    2
    Oh sorry, I should have made myself more clear.

    Problem solved anyway

    What I've done is used a void this time, finding I couldn't make the variables global there, then I put the variables somewhere else where they are global and hey presto, fixed

    Just to give you an idea of what I did;

    Code:
    IrrlichtDevice *device = 0;
    video::IVideoDriver* driver = 0;
    scene::ISceneManager* smgr = 0;
    IGUIEnvironment* guienv = 0;
    scene::IAnimatedMesh* q3levelmesh = 0;
    scene::ISceneNode* q3node = 0;
    scene::ITriangleSelector* selector = 0;
    void setup()
    {
           device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 32, false, true, true, 0);
        
           driver = device->getVideoDriver();
           smgr = device->getSceneManager();
           guienv = device->getGUIEnvironment();
           
           
           
        
    }
    And then I would place

    'setup();'

    in int main();

    and it works.

    But thanks for offering your help, 'tis appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM