static variables and includes?

This is a discussion on static variables and includes? within the C++ Programming forums, part of the General Programming Boards category; Of course, I don't know how the program looks, but something like a graphics context and a few things like ...

  1. #61
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Of course, I don't know how the program looks, but something like a graphics context and a few things like active textures might be global, but the class itself should certainly not set it.
    When using global variables, don't forget to use const-correctness.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #62
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    what?
    edit: ah i shell use an external function to set the active. why didnt i came to this idee *lol*

  3. #63
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    You can use an object to keep track of your graphics context. You could make it global.
    The class for this should have pointers for the active texture, for example and you can set/get it with appropriate functions in the class itself.
    This or something in lines with it what I believe mats is suggesting.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #64
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, I agree with Elysia - one, perhaps global, graphics context that "ties everything else up" is the common way to do graphics implementations.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #65
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    thats what i tried and it caused several errors:
    Code:
    // Somewhere in the example:
    	vglTexture tex;
    	tex.LoadFromFile("Media/Texture2.bmp");
            vglBindTexture(tex);
    
    
    // Declaration of vglTextur:
    vglTexture *vglTextur;
    
    // Somewhere in the code:
    void vglBindTexture(vglTexture tex) {
    	vglTextur = &tex;
    }

  6. #66
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    What do you this code does? It makes a copy of your texture and then assigns the address of it to a global pointer. But when the function exits, that copy is gone. Destroyed. Oops.
    Suggest you try what was outlined above.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #67
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    i'm a newbee and i dont understand it

  8. #68
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The incoming variable of "tex" in vglBindTexture() is a local copy of the object. Then you assign a global variable with the address of this variable, and leave the function - the local copy no longer exist.

    You can fix it by making the vglBindTexture take a pointer, and pass the address of your texture.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #69
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    You have no idea what passing by-value, by-pointer or by-reference is and you didn't know how to make a class and you're playing around with graphics and classes?
    I think you need to go back and try to learn a little more basics.
    Without proper basics, you won't get far.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 5 of 5 FirstFirst 12345
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classes as member variables
    By Stonehambey in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2008, 07:01 PM
  2. Includes making me insane >.<
    By IceDane in forum C Programming
    Replies: 14
    Last Post: 04-14-2008, 10:24 AM
  3. global variables
    By shadovv in forum C++ Programming
    Replies: 7
    Last Post: 10-24-2005, 02:21 PM
  4. MingW & ProperySheet
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 06-27-2002, 07:34 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21