Skip to main content
gamedev.net
🔒 Locked

Class Problem

Started by Luke1 7 replies 1k views
Original Post
Luke1
Luke1
I want to sort my code into classes so i made a class called CGAME and made "CGAME.H" and "CGAME.CPP" and when i goto compile it, it says: --------------------Configuration: CD - Win32 Debug-------------------- Compiling... CGAME.CPP d:\program files\microsoft visual studio\myprojects\cd\cgame.h(4) : error C2146: syntax error : missing '';'' before identifier ''InitialiseD3D'' d:\program files\microsoft visual studio\myprojects\cd\cgame.h(4) : error C2501: ''HRESULT'' : missing storage-class or type specifiers d:\program files\microsoft visual studio\myprojects\cd\cgame.h(4) : error C2061: syntax error : identifier ''HWND'' D:\Program Files\Microsoft Visual Studio\MyProjects\CD\CGAME.CPP(3) : error C2146: syntax error : missing '';'' before identifier ''InitialiseD3D'' D:\Program Files\Microsoft Visual Studio\MyProjects\CD\CGAME.CPP(3) : error C2501: ''HRESULT'' : missing storage-class or type specifiers D:\Program Files\Microsoft Visual Studio\MyProjects\CD\CGAME.CPP(3) : fatal error C1004: unexpected end of file found Error executing cl.exe. CGAME.OBJ - 6 error(s), 0 warning(s) any ideas on whats wrong here ? note that when i had all in my main.cpp it works fine ?
quasar3d
quasar3d
Did you place a ; after the class'' }

My Site
Luke1
Luke1
yep i have a ;
Stoffel
Stoffel
You need to include windows.h before you refer to the type HRESULT. Probably belongs at the top of CGAME.H.

With these errors, it was just lucky we''re able to see what''s going on. Usually, you should post the errors AND the code which generates the errors in order for us to better help you.

HTTP 500 strike 1..2..

Think Liberally.
Luke1
Luke1
Ok i made a main.h and put all my includes in there now i get these errors:

--------------------Configuration: CD - Win32 Debug--------------------
Compiling...
Main.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\CD\Main.cpp(5) : error C2146: syntax error : missing ';' before identifier 'eng'
D:\Program Files\Microsoft Visual Studio\MyProjects\CD\Main.cpp(5) : error C2501: 'CGAME' : missing storage-class or type specifiers
D:\Program Files\Microsoft Visual Studio\MyProjects\CD\Main.cpp(5) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Main.obj - 3 error(s), 0 warning(s)

heres my class declaration:

    
class CGAME
{
public:

HRESULT InitialiseD3D(HWND hWnd);
};


heres my class code:

                               
#include "CGAME.H"

HRESULT InitialiseD3D(HWND hWnd)
{
//First of all, create the main D3D object. If it is created successfully we

//should get a pointer to an IDirect3D8 interface.

g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if(g_pD3D == NULL)
{
return E_FAIL;
}

//Get the current display mode

D3DDISPLAYMODE d3ddm;
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
{
return E_FAIL;
}

//Create a structure to hold the settings for our device

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));

//Fill the structure.

//We want our program to be windowed, and set the back buffer to a format

//that matches our current display mode

d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
d3dpp.BackBufferFormat = d3ddm.Format;

//Create a Direct3D device.

if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
{
return E_FAIL;
}

return S_OK;
}


and my main.cpp


  
#pragma comment(lib,"d3d8.lib")
#include "main.h"

CGAME eng;

void Render()
{
if(g_pD3DDevice == NULL)
{
return;
}

//Clear the backbuffer to a green color

g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);

//Begin the scene

g_pD3DDevice->BeginScene();

//Rendering of our game objects will go here


//End the scene

g_pD3DDevice->EndScene();

//Filp the back and front buffers so that whatever has been rendered on the back buffer

//will now be visible on screen (front buffer).

g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

void CleanUp()
{
if(g_pD3DDevice != NULL)
{
g_pD3DDevice->Release();
g_pD3DDevice = NULL;
}

if(g_pD3D != NULL)
{
g_pD3D->Release();
g_pD3D = NULL;
}
}

void GameLoop()
{
//Enter the game loop

MSG msg;
BOOL fMessage;

PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);

while(msg.message != WM_QUIT)
{
fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);

if(fMessage)
{
//Process message

TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//No message to process, so render the current scene

Render();
}

}
}

//The windows message handler

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_KEYUP:
switch (wParam)
{
case VK_ESCAPE:
//User has pressed the escape key, so quit

DestroyWindow(hWnd);
return 0;
break;
}
break;

}

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

//Application entry point

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
//Register the window class

WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"cd", NULL};
RegisterClassEx(&wc);

//Create the application's window

HWND hWnd = CreateWindow("cd", "cdS",
WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
GetDesktopWindow(), NULL, wc.hInstance, NULL);

//Initialize Direct3D

if(SUCCEEDED(eng.InitialiseD3D(hWnd)))
{
//Show our window

ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);

//Start game running: Enter the game loop

GameLoop();
}

CleanUp();

UnregisterClass("cd", wc.hInstance);

return 0;
}





[edited by - Luke1 on January 3, 2003 2:49:23 PM]
stodge
stodge
You can''t post a question here everytime your code doesn''t compile. You obviously don''t fully yet understand what you''re trying to do.

Here''s a clue:

quote:
error C2501: ''CGAME'' : missing storage-class or type


It''s saying that it doesn''t know that CGAME is. So what do you need to do to introduce the CGAME class to the compiler?

....
....

Think it through....

....
....

Think some more....

....
....


#include "cgame.h"

Presuming your CGAME class definition is in cgame.h that is.


http://www.stodge.net - the powerhouse in personal commentary
---------------------http://www.stodge.net
Stoffel
Stoffel
ZE--are you saying stodge misspoke? He's 100% correct. Definition is the correct term (class definition). The variable definition of eng in MAIN.CPP won't work without the class definition of CGAME; a declaration isn't enough. Before that line, the author must #include "cgame.h", where he's shown us that the class CGAME is defined. Maybe I misread you?

Think Liberally.

[edited by - Stoffel on January 3, 2003 4:18:03 PM]
zealouselixir
zealouselixir
I misread. My apologies.
[twitter]warrenm[/twitter]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.