Working with multiple files?

Posts 1–3 of 3 · Page 1 of 1
Working with multiple files?
Hey guys. I've reached the point where I probably need to work in multiple files at once on a project. This is both good and bad. Is it hard to do it?

Could you guys explain how to do it? If you don't feel like writing several pages on how to do it, culd you please point me to good tutorials that taches it?

Thanks.
Include files is what you will want to look into.
Basically, you define functions, classes, structures, etc. inside your header files (.h) then write out actual function body code and such in the source (.cpp / c) files.

And no its not hard to do, its part of using C/C++.
You may also have multiple .cpp files but remember you need to make your function etc global
eg.
Code:
//PrintSomething.h
#include <stdio>
#include <cstdlib>

class Draw2Screen
{
public:
    bool PrintText(char* Text, ...);
    bool ClearConsole( void );
}
Code:
//PrintSomething.cpp
#include "PrintSomething.h"

bool Draw2Screen::PrintText( char* Text, ... )
{
    printf(Text);
    return 1;
}

bool Draw2Screen::ClearConsole( void )
{
    system( "cls" );
    return 1;
}


//Declare a new object called Draw
Draw2Screen Draw;
Code:
//main.cpp
#include "PrintSomething.h"

//Now declare that there's an external object...
extern Draw2Screen Draw;

int main( int argc, char** argv )
{
    Draw.ClearConsole( );
    Draw.PrintText( "Hello World" );

    return 0;
}
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us