Class and Bug Help: C3861

Can someone help me on this error?

in "cDef.h":

#pragma once class cDef { public: static int STATE_LOGO; static int STATE_MENU; static int MESSAGE_ENTER; static int MESSAGE_UPDATE; static int MESSAGE_PAINT; static int MESSAGE_EXIT; }; 

in "GameState.h":

 #pragma once #ifndef _GameState_ #define _GameState_ #include "cDef.h" class MainGame; class GameState; class GameState { public: MainGame *mg; int GAME_STATE_DEF; virtual void MessengeEnter(int message) = 0; virtual void MessengeUpdate(int message,int keys) = 0; virtual void MessengePaint(int message,CDC *pDc) = 0; void StateHandler(int message,CDC *pDc,int keys); public: GameState(void); public: ~GameState(void); }; #endif 

in "GameState.cpp":

 #include "StdAfx.h" #include "GameState.h" GameState::GameState(void) { GAME_STATE_DEF = -1; } GameState::~GameState(void) { } void GameState::StateHandler(int message,CDC *pDc,int keys) { if(message == cDef.MESSAGE_ENTER) { MessageEnter(message); } if(message == cDef.MESSAGE_UPDATE) { MessageUpdate(message,keys); } if(message == cDef.MESSAGE_PAINT) { MessagePaint(message,pDC); } } 

Mistake:

 warning C4832: token '.' is illegal after UDT 'cDef' see declaration of 'cDef' error C3861: 'MessageUpdate': identifier not found error C3861: 'MessageEnter': identifier not found error C3861: 'MessagePaint': identifier not found ... 

Thanks in advance!

0
c ++ visual-studio-2005
source share
3 answers

Here is what I used to clog my students, who were supposed to learn C ++, coming from Java, and were always confused about when to use :: , . and -> :

  • A::B means that A is either a class or a namespace name.
  • AB means that A is either an object or a reference to an object.
  • A->B means that A is either a pointer or an object of type with operator-> overloaded (aka "smart pointer")

If you know this, you can also apply them back, so if you have A and B , you know what to set between them.

(I think these rules should be extended to C ++ 11, but I'm not sure. If you know, feel free to add this.)

+2
source share

Static variables are accessed using the scope operator :: instead of the element access operator .

Example:

cDef::MESSAGE_ENTER

You must also initialize the cDef members in your cpp file to some value. In this case, perhaps a rename is likely to be better.

+1
source share

This seems obvious as soon as you see it - you declare a member function

 virtual void MessengeEnter(int message) = 0; 

but call

 MessageEnter(message); 

(note the difference between Messenge and Message )

+1
source share

All Articles