主.cpp:
#include <iostream>
#include "pokemonList.h"
void pokemonLookup();
int main() {
pokemonLookup();
return 0;
}
void pokemonLookup() {
pokemonList pL;
std::cout<<std::endl<<"What Pokemon do you want to look up? ";
std::string pokemonLookup;
std::cin>>pokemonLookup;
pL.displayPokemon(pokemonLookup);
}
口袋妖怪列表.h:
#ifndef POKEMONLIST_H
#define POKEMONLIST_H
#include <iostream>
class pokemonList
{
private:
struct pokemonTemplate {
std::string pokemonName;
std::string pokemonMoves[3];
int pokemonLevel;
int baseATK;
int baseDEF;
int baseSPATK;
int baseSPDEF;
int baseSPEED;
};
pokemonTemplate bulbasaur;
pokemonTemplate pikachu;
public:
void displayPokemon(std::string pokemon);
protected:
};
#endif // POKEMONLIST_H
口袋妖怪列表.cpp:
#include "pokemonList.h"
/*
pokemonTemplate* bulbasaur() {
bulbasaur.pokemonName = "Bulbasaur";
bulbasaur.pokemonMoves[3];
bulbasaur.pokemonLevel = 5;
bulbasaur.baseATK = 10;
bulbasaur.baseDEF = 10;
bulbasaur.baseSPATK = 10;
bulbasaur.baseSPDEF = 10;
bulbasaur.baseSPEED = 10;
}
pokemonTemplate* pikachu() {
pikachu.pokemonName = "Pikachu";
pikachu.pokemonMoves[3];
pikachu.pokemonLevel = 5;
pikachu.baseATK = 8;
pikachu.baseDEF = 10;
pikachu.baseSPATK = 12;
pikachu.baseSPDEF = 6;
pikachu.baseSPEED = 15;
}
*/
void displayPokemon(std::string pokemon) {
std::cout<<std::endl<<"Looking up: " + pokemon<<std::endl;
}
我意识到在 pokemonList.cpp 文件中我有一堆错误代码被注释掉了,这不是这个问题的意义所在。当我尝试编译时,我在 main.cpp 中得到一个错误,说:
D:/CodeBlocks/Projects/RelearningCPlusPlus/main.cpp:15: undefined reference to `pokemonList::displayPokemon(std::string)'