Anon
Anon

Reputation: 1354

including headers results in errors

for some reason i get multiple errors once i include my own header file, that has a simple class definition. Here is the code:

#define WIN32_LEAN_AND_MEAN 
#include "windows.h"
//#include "CInt.h"   <--- i get multiple errors once i activate this line

HINSTANCE       hInst;
HWND            wndHandle;

bool        initWindow(HINSTANCE hInstance);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    if (!initWindow(hInstance)) return false;

    MSG msg;
    ZeroMemory(&msg, sizeof(msg));

    while(true)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message == WM_QUIT) break;
    }

    return msg.wParam;
}

bool initWindow(HINSTANCE hInstance )
{
    WNDCLASSEX wcex;

    wcex.cbSize             = sizeof(WNDCLASSEX);
    wcex.style              = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc        = WndProc;
    wcex.cbClsExtra         = 0;
    wcex.cbWndExtra         = 0;
    wcex.hInstance          = hInstance;
    wcex.hIcon              = LoadIcon(0, IDI_APPLICATION);
    wcex.hCursor            = LoadCursor(0, IDC_ARROW);
    wcex.hbrBackground      = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
    wcex.lpszMenuName       = 0L;
    wcex.lpszClassName      = L"MOVEENGINE";
    wcex.hIconSm            = 0;

    RegisterClassEx(&wcex);

    wndHandle = CreateWindow(L"MOVEENGINE", L"MOVE ENGINE", WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, 0, 0, 1920, 1080, NULL, NULL, hInstance, NULL);

    if (!wndHandle) return false;

    ShowWindow(wndHandle, SW_SHOW);
    UpdateWindow(wndHandle);

    return true;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int iVirtKey = static_cast<int>(wParam);

    switch (message)
    {
        case WM_KEYDOWN:
            switch(iVirtKey)
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;
            }
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}

also code of the CInt.h:

class CInt
{
public:
    int k;

    CDirect3DDevice(int x):k(x){};
}

So what is wrong with my code? (I use Visual Studio 2010)

Upvotes: 2

Views: 169

Answers (2)

ssube
ssube

Reputation: 48267

Besides the missing semicolon dasblinkenlight pointed out, you also are initializing a member from a method that is not the constructor, here:

CInt::CDirect3DDevice(int x) : k(x) {};

This will cause errors, as members may only use the : k(x) syntax from the class' ctor, not other methods.

This looks like it could be a copy-paste-edit errors, but without posting the errors you're getting, there's no way to tell for sure.

Upvotes: 2

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726569

You are missing a semicolon after the class definition in your .h file.

Upvotes: 7

Related Questions