简体   繁体   中英

error C2039: 'get_quest_dynstr' : is not a member of '`global namespace'

I get this error

Error 2 error C2039: 'get_quest_dynstr' : is not a member of '`global namespace'' e:\\phase3a\\tdisk\\workspace\\cbs\\source\\cbs\\schedapp\\source\\treesearchbox.cpp 17 1 SchedApp

Error 3 error C2039: 'CheckCommand' : is not a member of '`global namespace'' e:\\phase3a\\tdisk\\workspace\\cbs\\source\\cbs\\schedapp\\source\\treesearchbox.cpp 21 1 SchedApp

When I try to compile my C++ application.

TreeSearchBox.hpp

#if !defined(TREE_SEARCH_BOX)
#define TREE_SEARCH_BOX

#include "standaloneconn.hpp"

class TREE_SEARCH_BOX : public STANDALONE_CONN
{
public: 
    TREE_SEARCH_BOX();
    virtual int get_quest_dynstr(int idquest, LPTSTR opstr, PDYNOBJ dynpobj);
    virtual int CheckCommand(PBASEWND pwnd, int idItem, HWND hwndCtl, int wNotifyCode, int indx);
    virtual LPTSTR  get_classname(){return _TEXT("TREE_SEARCH_BOX");}
};

#endif

TreeSearchBox.cpp

#include "cpptot.hpp"
#include "apptot.hpp"
#include "TreeSearchBox.hpp"
#include "lov.hpp"


//******************************************************************************
// Component: IFS/Scheduling
//
// File name: TreeSearchBox.cpp
// 
// Purpose:   Contains an object for connecting a standalone client directly to ORACLE
//              
// Ver          Date        Sign    History
// ---          ----        ----    -------
//              150604      FARFLK  Adding tree search functioanlity enhanced
//******************************************************************************    
int TREE_SEARCH_BOX::get_quest_dynstr(int idquest, LPTSTR opstr, PDYNOBJ dynpobj){
    return 0;//get_quest_dynstr(idquest, opstr, dynpobj);
}

int TREE_SEARCH_BOX::CheckCommand(PBASEWND pwnd, int idItem, HWND hwndCtl, int wNotifyCode, int indx){
    return 0;
}

I'm struggling for a long time on how to rectify this error. Please help me. What am i doing wrong?

In the beginning you have a guard block :

#if !defined(TREE_SEARCH_BOX)
#define TREE_SEARCH_BOX

which is good. But it does mean you call #define TREE_SEARCH_BOX which means TREE_SEARCH_BOX is defined as nothing. So when you compile, your preprocessor scans your files, and replaces TREE_SEARCH_BOX with . This is breaking your code, because you're now trying to compile this:

int ::get_quest_dynstr(int idquest, LPTSTR opstr, PDYNOBJ dynpobj){ ...

Where the :: means global namespace .

There are two ways to fix this:

  • change your guard block

      #if !defined(TREE_SEARCH_BOX_SOMETHING_ELSE) #define TREE_SEARCH_BOX_SOMETHING_ELSE 
  • change your class name.


What i do find interesting is that you don't get errors about the fact that you also try to compile:

class  : public STANDALONE_CONN{

But it turns out that you can define an anonymous class like this:

class : baseClass {

  //bla
};

i guess i learned something today :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM