I attempt to call a static member function like this:
ScratchPad::Draw(this, m_pGraphics);
The .h is this:
class ScratchPad
{
private:
static enum {MAX = 24};
// State variable
static bool m_MsgActive;
static wstring m_MessageText; // Warning messages
// Implementation of Scratch Text
static UINT16 m_top; // Top of "stack"
static wchar_t m_ScratchText[MAX+1]; // Scratchpad text
static void AddChar(char); // Add char to the scratchpad
static void DelChar(); // Delete last character entered
static void ClrScratchPad(); // Clear line
public:
static void PressKey(char); // Enters char pressed into scratchpad
static void Clr(); // Clears line of text (or message)
static void Del(); // Clears last key press
static void Draw(Cdu* pCdu, Gdiplus::Graphics* g);
};
And the function definition is:
void ScratchPad::Draw(Cdu* pCdu, Gdiplus::Graphics* g)
{
// Stuff here
}
However, the compiler gives me:
Error 1 error C2061: syntax error : identifier 'Cdu' c:\documents and
settings\patrick\my documents\visual studio 2005\projects\gauge
projects\bachwfms\bachwfms\inc\ScratchPad.h 42
Error 2 error C2061: syntax error : identifier 'Cdu' c:\documents and
settings\patrick\my documents\visual studio 2005\projects\gauge
projects\bachwfms\bachwfms\inc\ScratchPad.h 42
Error 3 error C2660: 'ScratchPad::Draw' : function does not take 2
arguments c:\Documents and Settings\Patrick\My Documents\Visual Studio
2005\Projects\Gauge Projects\BACHWFMS\BACHWFMS\Cdu\Cdu.cpp 61
After reading the help, I am still mystified.
Hard to say for sure without more context, but it looks to me like the
declaration of the Cdu class is not visible to the compiler when it tries to
compile your code. Before the declaration of ScratchPad, you need to at
least forward declare Cdu, as in:
class Cdu;
(you only need this much because you only declare a pointer to Cdu in the
declaration of ScratchPad).
Before the definition of
ScratchPad::Draw
you will need to have the full declaration of Cdu available (assuming that
you dereference the pointer to it inside the function).
--
John Carson
"John Carson" wrote:
>
> Hard to say for sure without more context, but it looks to me like the
> declaration of the Cdu class is not visible to the compiler when it tries to
> compile your code. Before the declaration of ScratchPad, you need to at
> least forward declare Cdu, as in:
>
> class Cdu;
>
> (you only need this much because you only declare a pointer to Cdu in the
> declaration of ScratchPad).
>
> Before the definition of
>
> ScratchPad::Draw
>
> you will need to have the full declaration of Cdu available (assuming that
> you dereference the pointer to it inside the function).
Thanks for your response.
I actually have
#include "Cdu.h" in the .h file.
And the class appears visible in that intellisense sees it and knows what it
is, so not sure that is it. Although I went a differenct route, I'm still
curious about this.
Try adding this at the top of your header file:
#ifdef Draw
#undef Draw
#endif
I'm not sure where it would be coming from, but I'm suspicious that you've
got a macro named Draw somewhere.
-cd
I'm out of ideas. If you can strip out inessential details and post code
exhibiting the problem that we can try with our own compilers, then we may
be able to diagnose the problem.
--
John Carson
>I should mention that the function works fine with only the m_pGraphics
>parameter in the call. For some reason, if my object trys to call the other
>object's static Draw() method with a pointer to itself (this) it then won't
>work. But works fine when I added a 2nd parameter that is not a pointer to
>the invoking object.
As you know, overloading doesn't span scopes, so if your actual code
differs WRT inheritance from what you posted, such that you're expecting
base and derived class functions to overload, that would explain the error.
--
Doug Harrison
Visual C++ MVP