关于类和错误的帮助:C3861 [英] Help about class and error: C3861

查看:248
本文介绍了关于类和错误的帮助:C3861的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我处理这个错误吗?

Can someone help me in this error?

在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;
};

#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

#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);
    }
}

错误:

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
...

提前感谢!

推荐答案

敲入我的学生谁必须学习C ++来自Java,总是困惑,什么时候使用 :: - >

Here's what I used to hammer into my students who had to learn C++ coming from Java and always were confused about when to use ::, ., and ->:


  • :B 表示 A 是类或命名空间名称。

  • AB 表示 A 是对象或对象的引用。

  • A-> B 表示 A operator-> 重载(又称为智能指针)类型的对象

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

如果你知道这些,你也可以反向应用它们,如果你有一个 A B ,你知道把什么放在之间。

If you know these, you can also apply them backwards, so that if you have an A and a B, you know what to put in between.

(我认为这些规则必须扩展为C ++ 11,但我不确定,如果你知道,请随意添加。)

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

这篇关于关于类和错误的帮助:C3861的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆