简体   繁体   English

函数不是全局名称空间的成员

[英]function is not a member of global namespace

So I'm attempting to program chess in C++ and I decided to make my move handler its own class (it was a main function before) so I could use it in some of my other classes without having to copy it everywhere. 因此,我尝试用C ++编写国际象棋,然后决定将移动处理程序设为自己的类(之前它是主要功能),这样我就可以在其他一些类中使用它,而不必将其复制到各处。

However, when I finished setting everything up I got this error: 'parseMove' : is not a member of '`global namespace'' 但是,当我完成所有设置后,出现以下错误:'parseMove':不是'`global namespace'的成员

I'm using the standard namespace and all public functions and variables, and I know that so please don't bring it up unless it's relevant. 我正在使用标准名称空间以及所有公共函数和变量,并且我知道,因此除非相关,否则请不要提出它。 My IDE is MS Visual C++ 2012. 我的IDE是MS Visual C ++ 2012。

Here is the code: 这是代码:

In the main: 在主要方面:

void playGame(){
      ...
MoveParser parser;      //declare move handler
      ...
//example of use
parser.parseMove(current, currentX, currentY);
      ...
}

MoveParser.h: MoveParser.h:

#pragma once
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

class MoveParser
{
public:
MoveParser(void);
~MoveParser(void);

void parseMove(string, int &, int &);
};

MoveParser.cpp: MoveParser.cpp:

#include "MoveParser.h"


MoveParser::MoveParser(void)
{
}


MoveParser::~MoveParser(void)
{
}

void::parseMove(string str, int &x, int &y){

//random junk

}

And also Visual C++ is giving me some new errors that aren't real...and I know they're not real because the code that it's giving me errors on ran fine before I added the new class and I haven't changed it. 而且Visual C ++给了我一些新的错误,这些错误不是真实的...我知道它们不是真实的,因为在我添加新类之前,它给我带来错误的代码运行良好,而且我没有更改。

Anyways, very frustrating, hopefully someone can point me in the right direction. 无论如何,非常沮丧,希望有人能指出我正确的方向。

You forgot to specify the class name before the function name in its definition. 您忘记在其定义中的函数名称之前指定类名称。 Change this code 更改此代码

void::parseMove(string str, int &x, int &y){

//random junk

}

to

void MoveParser::parseMove(string str, int &x, int &y){

//random junk

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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