views:

131

answers:

6

Hi all, I have a very strange problem and the following code wont compile:

#ifndef MYWINDOW_HPP_INCLUDED
#define MYWINDOW_HPP_INCLUDED

class MyWindow{

    private:
        WNDCLASSEX window_class;
        HWND window_handle;
        HDC device_context_handle;
        HGLRC open_gl_render_context;
        MSG message;
        BOOL quit;

    public:
        Window(int height=416, int width=544, WindowStyle window_style=WINDOWED);
        void Show();
        void Close();
        ~Window();

};

#endif // MYWINDOW_HPP_INCLUDED

I get the following error: error: expected '=', ',', ';', 'asm' or 'attribute' before 'MyWindow'

I can't see any syntax errors here, although I coukd be wrong as I am very (very) new in c++. Thanks in advance, ell.

EDIT: Yeah, I tried renaming my class to MyWindow from Window to solve the problem but it didn't work, I forgot to rename the constructor. I have updated the code now but that still hasn't solved the problem. Here is the only other code I have in my project, I linked it because adding al those spaces would take a while: here's the code

+1  A: 

Most likely your problem comes before the posted file. In the including file or a previous include.

Steve Fallows
This sometimes happens to me when I forget the semicolon after the class definition. It starts complaining about the class in the *next* included header.
Thomas
With candidates being missing `;`, `}` etc.
Georg Fritzsche
+1  A: 

A couple of things - you need to have:

 #include <windows.h>

somewhere in your code. And if:

 Window(int height=416, int width=544, WindowStyle window_style=WINDOWED);

is supposed to be a constructor, it should ne:

 MyWindow(int height=416, int width=544, WindowStyle window_style=WINDOWED);
anon
A: 

You're using semi-colons after your function definitions. Remove them. (Referring to your pastebin code.)

Fredrik Ullner
If by definition you mean after the close curly brace after the actual function, I have tried removing these but it doesn't help
Ell
+1  A: 

This header isn't being compiled as C++, so the compiler doesn't recognize "class" as a reserved word. I was getting this error, and it was because I was trying to include a C++ header in an Objective-C source file, and the solution was to use a stripped-down straight-C header for inclusion from Obj-C.

-- Fellow C++ noob who just ran into this.

Travis
+1  A: 

Are you sure that you're using g++ rather than gcc? It's a dumb question, but the class keyword in C++ isn't a keyword in C, which might trigger such a warning. Untested theory, but I've run into that a couple of times.

Dustin
A: 

Ahh, silly me, I had main saved as a .c file instead of .cpp, resulting in Code::Blocks trying to compile it as in c instead of c++, thanks for your help guys!

Ell