Thread: globals and splitting up your source

  1. #1
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62

    globals and splitting up your source

    do guru level c++ programmers always minimize the use of globals?

    and do they split up their code into nice small .cpp and .h files? I just made a large program and it has one small header file and one huge cpp file. Everytime i try to split it up i get undeclared identifier errors because the code is so un-modular.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    29
    I'm not a guru, I have to learn really a lot , but I think it's about basic concept. If you are creating a big program, you should choose between some basic concepts: object programming, modular programming, and other; or you can just code it, so you'll work out a big cpp program, that cannot be divided
    (I haven't written a really big program, my largest had about 4000 lines with headers and all that stuff, so about 1000 lines of my own code. I divided it into about 10 cpp files, but maybe it was too many: I didn't know how to use projects so it was a nice mess there..)
    Maybe you can read some tutorial(I had one downloaded, but I don't know from where) about basic concepts.
    Also programming language should be chosen according to your concept, for example pure C isn't good for object programming.. C++ is much more better.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    split up different things such as seperate classes taht are independant from everything else. if its not exactly independant, then comment your code and say what it needs. if it is independant, compile the code to an object for faster compiling (or start add the file to the VC++ project).

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >Everytime i try to split it up i get undeclared identifier errors
    >because the code is so un-modular.

    I guess you're splitting up the code in different files isn't it? When you have declared a global variable in file A and you also use it in file B, then in file B you have to declare it as extern, so the compiler knows about the variable and it also knows that it is declared somewhere else.

    File A:

    int my_global;

    File B:

    extern int my_global;

  5. #5
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    arr i see !!!! thank you very much shiro

Popular pages Recent additions subscribe to a feed