Really confusing error

This is a discussion on Really confusing error within the C++ Programming forums, part of the General Programming Boards category; Ok to start, here's the beginning of my program (a simple OpenGL program): Code: #include <windows.h> #include <gl\gl.h> #include <gl\glu.h> ...

  1. #1
    myNegReal
    Join Date
    Jun 2005
    Posts
    100

    Really confusing error

    Ok to start, here's the beginning of my program (a simple OpenGL program):
    Code:
    #include <windows.h>	
    #include <gl\gl.h>		
    #include <gl\glu.h>
    #include "input.h"
    #define WIN32_LEAN_AND_MEAN
    
    HDC hDC=NULL;
    HGLRC hRC=NULL;
    HWND hWnd=NULL;
    HINSTANCE hInstance;
    Input.h is as follows:
    Code:
    #ifndef INPUT_H
    #define INPUT_H
    #define INITPRESSONLY (0 | 128)
    
    class Input {
          public:
                 static bool vkeys[256];
                 static void markInitialPressOnly(int num, int* flags) {
                        for (int i=0;i<num;vkeys[flags[i++]] = INITPRESSONLY);
                 }
                 static void unmarkInitalPressOnly(int num, int* flags) {
                        for (int i=0;i<num;vkeys[flags[i++]] = false);
                 }
    }
    #endif // INPUT_H
    Used to hold pressed keys, with a simple interface to tell if you want it to be only detected on initial press.
    The problem I'm getting is that it says HDC does not name a type. So I moved it to a static variable in WinMain instead of a global variable. It was fine. Then it said HGLRC does not name a type. Is there something wrong with my class? Is my header file messing with the windows API? Am I not including correctly? When I don't include it, the program is fine. I'm using Dev-C++, anyone know what may be wrong?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    1. Your class is missing a final ; at the end
    2. vkeys[flags[i++]] = INITPRESSONLY) is abusing the bool type.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    in
    Code:
    #define INITPRESSONLY (0 | 128)
    0 OR 128 = 128

    Why not just put 128?

  4. #4
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    0 OR 128 = 128

    Why not just put 128?
    I know, but as Salem said, you're not normally supposed to really do that with bools, so I did it just in case. The experience I've had with bools, it's better to use bitwise operators, but maybe not. I'll check up on it.
    lol thanks Salem, I can't believe I missed that semi-colon. Must've been my recent addiction to FF7 lol, I've been doing nothing but playing it for days.

  5. #5
    *this
    Join Date
    Mar 2005
    Posts
    498
    Well ya I know that it's not right to do it, but theres no reason for OR'ing 0 and 128... It doesnt make sence...It doesnt even take a variable, its just one number so why not put the resulting number there. The compiler replaces it with 0 | 128, causeing there to be an unnecessary OR in your algorithm. Just thought I'd point that out.

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    FF7 rocks. It's off topic, but I'm hooked on Timesplitters: Future Perfect right now
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

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