Erreur: définition multiple de `gamekey :: getGameKeywords() »multiple Définition C++ [Erreur]
GameKey.cpp et .h erreur de la cause, alors que ExitKey.cpp et .h sont essentiellement la même classe et tête exacte mais ne produisez pas d'erreur.
(je sais toute chose sur l'utilisation namespace 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;
}
Merci pour toute aide!
Est-il possible que vous ayez un autre fichier (non 'GameKey.cpp') qui définit' gamekey :: getGameKeywords() '? – Rakete1111
Veuillez publier un [Exemple minimal, complet et vérifiable] (http://stackoverflow.com/help/mcve). Impossible de reproduire dans mon environnement local (Windows 7, gcc 4.8.1, compile commande = 'g ++ ExitKey.cpp GameKey.cpp main.cpp -o main') Le contenu de' main.cpp' est 'int main() {} ' – MikeCAT
@ Rakete1111 Malheureusement je ne pense pas. – Sean