none
自定义类出现  error C2065: “pClickNum”: 未声明的标识符 RRS feed

  • 问题

  • 自定义类的 .h文件有声明

    //菜单点击重新开始游戏按钮
        virtual void restartClick();
      //获得点击次数
        virtual int getClickNum();
    private:
        //当前关卡的点击次数
        int pClickNum;
    

    cpp 中 :

     void ZRBLayerLevel1::restartClick()
    {    
    }
    int ZRBLayerLevel1::getClickNum(){
        return pClickNum;
    }
     
    vs 未提示语法错误,编译时却有
    ‘error C2509: “restartClick”: 成员函数没有在“ZRBLayerLevel1”中声明
    error C2065: “pClickNum”: 未声明的标识符’

    这该怎么解决?

    2014年6月1日 8:34

答案

  • 你好,

    我按照你的描述重现了你的问题,没有任何编译错误。

    我建了一个头文件叫Header.h:

    class tt{
    
    	virtual void restartClick();
    	//获得点击次数
    	virtual int getClickNum();
    private:
    	//当前关卡的点击次数
    	int pClickNum;
    
    };

    然后在.cpp 文件中实现如下:

    / test.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include "Header.h"
    #define SIZE 5
    using namespace std;
    
    void tt::restartClick()
    {
    }
    
    
    int tt::getClickNum(){
    	return pClickNum;
    }
    
    
    
    int main()
    {
    	return 0;
    }
    

    编译结果如下:

    1>------ Build started: Project: test, Configuration: Release Win32 ------

    1>  test.cpp

    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月10日 6:12

全部回复

  • 你好,

    根据你的错误,应该是你没有把头文件包含到使用的类实现文件中。在 ZRBLayerLevel1的实现文件中,添加#include"你的自定义类的头文件"。

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月2日 9:21
  • 已经包含了

    ZRBLayerLevel1 中有:

    #include "ZRBLayerLevel1.h"

    2014年6月4日 1:13
  • 你好,

    我按照你的描述重现了你的问题,没有任何编译错误。

    我建了一个头文件叫Header.h:

    class tt{
    
    	virtual void restartClick();
    	//获得点击次数
    	virtual int getClickNum();
    private:
    	//当前关卡的点击次数
    	int pClickNum;
    
    };

    然后在.cpp 文件中实现如下:

    / test.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include "Header.h"
    #define SIZE 5
    using namespace std;
    
    void tt::restartClick()
    {
    }
    
    
    int tt::getClickNum(){
    	return pClickNum;
    }
    
    
    
    int main()
    {
    	return 0;
    }
    

    编译结果如下:

    1>------ Build started: Project: test, Configuration: Release Win32 ------

    1>  test.cpp

    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月10日 6:12