エラー:GameKey :: getGameKeywords()」C++複数の定義[エラー]
GameKey.cppと.H原因エラー `の複数の定義、基本的に全く同じクラスとヘッダ.HありExitKey.cppながらエラーは発生しません。
(私は名前空間stdを使用する方法について全体のことを知っている)
//Function Declarations
#ifndef GAMEKEY_H
#define GAMEKEY_H
// C++ libraries
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
class GameKey
{
private:
string keyString;
string lineData;
public:
// Default constructor
GameKey();
// Deconstructor
~GameKey();
// Get keywords
string getGameKeywords();
};
#endif
GameKey.cpp
//Function Definitions
#include "GameKey.h"
// Constructor
GameKey::GameKey()
{
}
// Deconstructor
GameKey::~GameKey()
{
}
// Get keywords
string GameKey::getGameKeywords()
{
ifstream infile;
infile.open("GameKey.txt");
while (getline(infile, lineData))
{
keyString.append(lineData);
keyString.append("\n");
}
infile.close();
return keyString;
}
ExitKey.h
//Function Declarations
#ifndef EXITKEY_H
#define EXITKEY_H
// C++ libraries
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
class ExitKey
{
private:
string keyString;
string lineData;
public:
// Default constructor
ExitKey();
// Deconstructor
~ExitKey();
// Get keywords
string getExitKeywords();
};
#endif
ExitKey.cpp
//Function Definitions
#include "ExitKey.h"
// Constructor
ExitKey::ExitKey()
{
}
// Deconstructor
ExitKey::~ExitKey()
{
}
// Get keywords
string ExitKey::getExitKeywords()
{
ifstream infile;
infile.open("ExitKey.txt");
while (getline(infile, lineData))
{
keyString.append(lineData);
keyString.append("\n");
}
infile.close();
return keyString;
}
助けてくれてありがとう!
それはあなたが別のファイル 'GameKey :: getGameKeywordsを定義します(ない' GameKey.cpp'を)() '持っていることは可能ですか? – Rakete1111
[最小限で完全であり、検証可能な例](http://stackoverflow.com/help/mcve)を投稿してください。 'main.cpp'の内容は' int main() 'です。これは、ローカルの環境(Windows 7、gcc 4.8.1、コンパイルコマンド=' g ++ ExitKey.cpp GameKey.cpp main.cpp -o main') {} ' – MikeCAT
@ Rakete1111残念ながら私はそうは思わない。 – Sean