我正在尝试使用 play() 函数设置一个新类。我不确定我做错了什么,因为我有其他以类似方式实现的类,它们工作正常。有人可以指出我可能在哪里犯了错误吗?
.h 文件
#ifndef GAME_H
#define GAME_H
#include <string>
using namespace std;
class Game {
public:
Game();
void play();
};
#endif
.cpp 文件
#include "game.h"
#include <string>
#include <iostream>
using namespace std;
Game::Game() {}
Game::play() {}
我调用 play 函数如下:
Game* theGame = new Game();
theGame->play();
编译时出现以下错误:
game.cpp:10: error: ISO C++ forbids declaration of ‘play’ with no type
game.cpp:10: error: prototype for ‘int Game::play()’ does not match any in class ‘Game’
game.h:16: error: candidate is: void Game::play()
game.cpp:10: error: ‘int Game::play()’ cannot be overloaded
game.h:16: error: with ‘void Game::play()’