• Advertisement
Sign in to follow this  

Compiler not recognizing derived cApp class

This topic is 4177 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, I'm using MS VC++ 7.0.net compiler on an AMD64x2 4800 system with 2048 Megs RAM I have a simple WinMain Function that calls a cApp class to run my application. The cApp class is a derived class from a base class I developed called d3dApp. Anyways, the MS VC++ 7.0 Intellisense recognizes the base class functions (of which Run() is a member), yet when I attempt to compile the program, I get WinMain.cpp(64): error C2039: 'Run' : is not a member of 'cApp' Here is my code: WinMain.cpp WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow) { cApp App; return App.Run(); } WinMain.h class cApp : public d3dApp { private: // Graphics device, camera, and font cGraphics m_Graphics; public: cApp(); // Overridden functions bool Init(); bool Shutdown(); bool Frame(); }; SystemInitialize.h (A header I use to store all my base classes) class d3dApp { private: HINSTANCE m_hInst; HWND m_hWnd; protected: char m_Class[MAX_PATH]; char m_Caption[MAX_PATH]; WNDCLASSEX m_wcex; DWORD m_style; DWORD m_XPos; DWORD m_YPos; DWORD m_Width; DWORD m_Height; public: d3dApp(); HWND GethWnd(); HINSTANCE GethInst(); bool Run(); bool Error(BOOL Fatal, char *Text, ...); bool Move(long XPos, long YPos); bool Resize(long Width, long Height); bool ShowMouse(BOOL Show = true); virtual FAR PASCAL MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(hWnd, uMsg, wParam, lParam); } virtual bool Init() { return true; } virtual bool Shutdown() { return true; } virtual bool Frame() { return true; } static d3dApp *g_pApplication = NULL; static long FAR PASCAL d3dAppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); enum Task { IDLE = 0, INITIALIZE, SHUTDOWN_CLEANUP, DRAWFRAME }; }; Can anyone tell me why this won't compile, even though the Intellisense recognizes the base class? Thanks in advance, Sturm

Share this post


Link to post
Share on other sites
Advertisement
The code you posted is obviously not the same as the code you are actually using, seeing as the error is located on line 64 but you only show five lines of the source file. The code you've shown looks fine by itself, therefore the problem is probably somewhere in the code that you haven't shown.

Share this post


Link to post
Share on other sites
was just attempting to reduce space (I think.... ;) )

anyways, here is the full WinMain.cpp

// Includes
#include "WinMain.h"
#include "SystemInitialize.h"

// #define FULLSCREENMODE

cApp::cApp()
{
m_Width = 640;
m_Height = 480;
m_style = WS_BORDER | WS_CAPTION | WS_OVERLAPPEDWINDOW | WS_SYSMENU;
strcpy(m_Class, "GameClass");
strcpy(m_Caption, "3D EngineShell");
}

bool cApp::Init()
{
// Initialize the graphics device
m_Graphics.Init();

// Determine to use fullscreen mode or not
#ifdef FULLSCREENMODE
m_Graphics.SetMode(GethWnd(), false, true, 640, 480);
#else
m_Graphics.SetMode(GethWnd(), true, true);
#endif

// Set perspective
m_Graphics.SetPerspective(0.6021124f,1.33333f,1.0f,20000.0f);

// Enable cursor
ShowMouse(true);

return true;
}

bool cApp::Shutdown()
{
// Shutdown and cleanup code goes here
m_Graphics.Shutdown();
return true;
}

bool cApp::Frame()
{
// Frame Drawing code here
return true;
}

WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
cApp App;
return App.Run();
}




Does that help? :)

Share this post


Link to post
Share on other sites
WinMain.h and SystemInitialize.h would also be useful, preferably in [source] tags.

Σnigma

Share this post


Link to post
Share on other sites
WinMain.h

[SOURCE]
#ifndef _WINMAIN_H_
#define _WINMAIN_H_

class cApp : public d3dApp
{
private:
// Graphics device, camera, and font
cGraphics m_Graphics;

public:
cApp();

// Overridden functions
bool Init();
bool Shutdown();
bool Frame();
};

#endif
[/SOURCE]


and SystemInitialize.h

[SOURCE]
#ifndef D3D_SYSTEMINITIALIZE_H_
#define D3D_SYSTEMINITIALIZE_H_

// Windows includes
#include <windows.h>
#include <time.h>

// Standard ANSI-C includes
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdarg.h>

// DirectX includes
#include "d3d9.h"
#include "d3dx9.h"
#include "dmusici.h"
#include "dsound.h"
#include "dinput.h"

//Com Include
#include <InitGuid.h>

// Define directives

#define ReleaseCOM(x) if(x) { x->Release(); x = NULL; }

class d3dApp
{
private:
HINSTANCE m_hInst;
HWND m_hWnd;

protected:
char m_Class[MAX_PATH];
char m_Caption[MAX_PATH];

WNDCLASSEX m_wcex;

DWORD m_Style;
DWORD m_XPos;
DWORD m_YPos;
DWORD m_Width;
DWORD m_Height;

public:
d3dApp();

HWND GethWnd();
HINSTANCE GethInst();

bool Run();
bool Error(BOOL Fatal, char *Text, ...);

bool Move(long XPos, long YPos);
bool Resize(long Width, long Height);

bool ShowMouse(BOOL Show = true);

virtual FAR PASCAL MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(hWnd, uMsg, wParam, lParam); }
virtual bool Init() { return true; }
virtual bool Shutdown() { return true; }
virtual bool Frame() { return true; }

static d3dApp *g_pApplication = NULL;
static long FAR PASCAL d3dAppWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

};

#endif

[/SOURCE]

Share this post


Link to post
Share on other sites
You need to #include "SystemInitialize.h" at the top of WinMain.h.

In addition, please note that the identifier _WINMAIN_H_ is reserved for compiler and standard library writer implementors (all identifiers starting with an underscore followed by a capital letter are reserved at global scope) and should not be used. Use something like PROJECT_PREFIX_WINMAIN instead. Also the headers <time.h>, <stdio.h>, <stdlib.h>, <math.h>, <string.h> and <stdarg.h> are deprecated in C++ and replaced with <ctime>, <cstdio>, <cstdlib>, <cmath>, <cstring> and <cstdarg>. Further more, <cstdio> is discouraged in C++ in favour of type-safe, length-safe iostreams and variable arguement lists are just plain evil.

Σnigma

Share this post


Link to post
Share on other sites
Enigma, thanks for the help!

Also, thinking more on this problem, I am wondering if the error is due to a dependancy or some other factor that I'm not considering, or not?

Am I missing a declaration of the class, somewhere?

As in

[SOURCE]
#ifndef _WINMAIN_H_
#define _WINMAIN_H_

class cApp; // declaration <<--- Necessary or no?

class cApp : public d3dApp
{
private:
// Graphics device, camera, and font
cGraphics m_Graphics;

public:
cApp();

// Overridden functions
bool Init();
bool Shutdown();
bool Frame();
};

#endif
[/SOURCE]
[/source]

Again, thank you for your help!

- Sturm

Share this post


Link to post
Share on other sites
Enigma,

I'm tired :) but your help was invaluable in getting my code to compile, which I am glad to say it has now.

Also, I took your recommendations for redefining my #ifndef / #define header to _MYD3D_MAIN_H_

I'll have to look through my code for the deprecated headers and see if I need to update some code as well.

Thanks much for pointing a tired programmer in the right direction.

- Sturm

Share this post


Link to post
Share on other sites
The definition of d3dApp needs to be known before you can define cApp. This is why you need to include the header that defines d3dApp before you define cApp. You'll also need to include the header which defined cGraphics since you have an member variable of that type held by value:

// nice legal include guards
#ifndef STURMRITTER_WINMAIM
#define STURMRITTER_WINMAIN

#include "SystemInitialize.h" // bring in the definition of d3dApp
#include "header_which_contains_cGraphics_definition.h"

class cApp : public d3dApp
{
private:
// Graphics device, camera, and font
cGraphics m_Graphics;

public:
cApp();

// Overridden functions
bool Init();
bool Shutdown();
bool Frame();
};

#endif

Σnigma

Share this post


Link to post
Share on other sites
Quote:
Original post by sturmritter
Also, I took your recommendations for redefining my #ifndef / #define header to _MYD3D_MAIN_H_


Almost, but not quite.

You still have an identifier that starts with an underscore followed by a capital letter.

I'd just change it to #ifndef / #deine MYD3D_MAIN_H

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement