Question

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.

However, when I finished setting everything up I got this error: 'parseMove' : is not a member of '`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.

Here is the code:

In the main:

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

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:

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

Anyways, very frustrating, hopefully someone can point me in the right direction.

Était-ce utile?

La solution

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

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top