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; Most likely, the compiler doesn't know what the type vglTex is - you need to include the appropriate header file ...

  1. #46
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Most likely, the compiler doesn't know what the type vglTex is - you need to include the appropriate header file for that class.

    --
    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.

  2. #47
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    i wanna define that object in vurtialGL.cpp and the class is defined in virtualGL.h
    i dont include that file, because it is automaticly included isnt it?

    well you see the source code i uploaded lately (..._demo3.zip)
    what is it that i'm doing wrong? i think i might mis understood the usage of header files as well as several other mistakes... tell me please
    Last edited by Devils Child; 01-30-2008 at 08:11 AM.

  3. #48
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, there are no "automatically included" header files - anywhere.

    --
    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.

  4. #49
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    The best thing to do is break classes into their own source files/headers so you can freely include those headers anywhere.
    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.

  5. #50
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    these include issues are so over complicated... what exactly does every of these 7 files include?

  6. #51
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Includes are not complicated. You must simply include a file that contains a declaration of definition of what you're trying to use.
    So make a vglTex.cpp file to contain the implementation. The source file should include vglTex.h, which contains the class definition, and all files that uses the class vglTex should also include vglTex.h.
    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. #52
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    dont know what i am doing wrong but it sure is my fault: i mean, i'm not very sure about all this. this works well, but as soon as i need classes, everything stops working well...

    sample.cpp
    Code:
    #include <string>
    #include "SDL/SDL.h"
    #include "VGL-Inc/VirtualGL.h"
    #include "VGL-Inc/Matrix.h"
    #include "VGL-Inc/Utility.h"
    virtualGL.cpp
    Code:
    #include <string>
    #include <time.h>
    #include "SDL/SDL.h"
    #include "Matrix.h"
    #include "Utility.h"
    virtualGL.h
    Code:
    #include "SDL/SDL.h"
    #include "Utility.h"
    matrix.cpp
    Code:
    #include "VirtualGL.h"
    matrix.h
    Code:
    //
    utility.cpp
    Code:
    #include "SDL/SDL.h"
    utility.h
    Code:
    //nothing included here
    Last edited by Devils Child; 01-30-2008 at 08:37 AM.

  8. #53
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    To rule out circular dependencies, you can try to break it out into its own source file/header as I mentioned.
    I don't know where the class is used (and I believe it's defined in VirtualGL.h).
    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.

  9. #54
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    yes it is.
    anyhow... what do you want me to do now that you see my include structure?

  10. #55
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Split the class into its own files.
    If you include the correct header and it still isn't working, then either your compiler is broken (unlikely) or you have circular dependencies - ie file A includes file B and file B includes file A.
    Plus if you split it, it will much easier to debug what it isn't working if it's not working.
    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.

  11. #56
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    hey cool man
    it's working when i use an external header file for the class
    thanks again
    i'll be here when something doesnt work again and i dont get it.

  12. #57
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    oh there is another tricky problem (sorry):

    VirtualGL.cpp:
    Code:
    vglTexture *vglTextur;
    Classes.h:
    Code:
    class vglTexture {
    private:
    public:
    	int w, h, buf[257][257];
    
    	void LoadFromFile(char path[]) {
    		SDL_Surface *image = SDL_LoadBMP(path);
    		w = image->w;
    		h = image->h;
    		if (w > 256) w = 256;
    		if (h > 256) h = 256;
    		for (int y = 0; y <= h; y++) {
    			for (int x = 0; x <= w; x++) {
    				buf[x][y] = GetPixel(image, x, y);
    			}
    		}
    		SDL_FreeSurface(image);
    	}
    
    	void SetActive() {
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    		vglTextur = this;
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    	}
    };
    of course the vglTexture variable is not defined at this point, but it can not be defined there because the class doesnt even exist yet...
    i guess there is a pretty easy solution for this umh...

  13. #58
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    This is very bad programming. Do not use global variables and using a class to set an active global pointer is just another bad programming step.
    Objects are self-contained. They do all the necessary work to function and expose interfaces for the programmer to work with them. There shouldn't be a SetActive function to set a global pointer to this class there.

    Each function that works with such a class should instead take an argument to a vglTexture object, and not use a global "active" pointer.

    And I stressed this before, implement the functions in the source file, not the header.
    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.

  14. #59
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    sure it is bad programming, but how does the program know which texture is the active one?
    you mean that i should add a parameter to the texture class such as "bool active;" ? how would that work? i dont even know how to iterate trough classes

  15. #60
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    By doing something like "ActiveTexture = SomeTexture;"

    Most graphics environments have a "Graphics Context", which is some sort of object/structure that contains "everything current" (or active to use your term). There are calls to "SetActiveXXXX", where XXX may be texture, pen/brush, etc, etc.

    --
    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.

Page 4 of 5 FirstFirst 12345 LastLast
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