即使我的函数全部定义,也会在C 中获得不确定的引用
Getting an undefined reference to error in c++ even though I have the functions all defined
enum state{
state_Mmenu, // State 0
state_settingmenu, // State 1
state_gamemenu, // State 2
state_savegamemenu, // State 3
state_loadgamemenu, // State 4;
state_Exit, // State 5;
state_other
};
state stateMmenu();
state statesettingmenu(string, string);
state stategamemenu();
state statesavegamemenu(string, string, string, ofstream&);
state stateloadgamemenu(string, string, string, ifstream&);
state stateExit();
int main()
{
state curr=state_other;
string filename= "PlayerOne.jak";
string fname="Player";
string lname="One";
ifstream inFS;
ofstream outFS;
while(curr != state_Exit)
{
switch(curr)
{
case state_Mmenu:
curr = stateMmenu();
break;
case state_settingmenu:
curr = statesettingmenu(fname, lname);
break;
case state_gamemenu:
curr = stategamemenu();
break;
case state_savegamemenu:
curr = statesavegamemenu(fname, lname, filename, outFS);
break;
case state_loadgamemenu:
curr = stateloadgamemenu(fname, lname, filename, inFS);
break;
default:
cout << "Don't Tip the Vending Machine"<<endl;
curr = state_Mmenu;
break;
}
}
return 0;
}
state statesavegamemenu(string fname, string lname, string filename,
ofstream outFS)
{
state next=state_savegamemenu;
int choice4=0;
cout<<" -Save Game Menu-----------------"<<endl;
cout<<"1. File Name - "<<filename<<endl;
cout<<"2. Save" <<endl;
cout<<"3. Game Menu" <<endl;
cout<<"----------------------------"<<endl;
do
{
cout << "Choice? "<< endl;
cin >> choice4;
cin.clear();
cin.ignore(10000,'n');
}while(!cin.good());
switch(choice4)
{
case 1:
{
cout<<"What would you like to save this file as? ";
cin>>filename;
cout<<endl;
next = state_savegamemenu;
}
break;
case 2:
{
outFS.open(filename.c_str());
if(!outFS.is_open())
{
next = state_savegamemenu;
break;
}
else
{
outFS<<fname<<endl;
outFS<<lname<<endl;
}
outFS.close();
next = state_savegamemenu;
}
break;
case 3:
next = state_gamemenu;
break;
default:
cout << "Bad Input!"<<endl;
next = state_savegamemenu;
break;
}
cout <<endl;
return next;
}
state stateloadgamemenu(string fname, string lname, string filename,
ifstream inFS)
{
state next=state_loadgamemenu;
int choice5=0;
cout<<" -Save Game Menu-----------------"<<endl;
cout<<"1. File Name - "<<filename<<endl;
cout<<"2. Load" <<endl;
cout<<"3. Main Menu" <<endl;
cout<<"----------------------------"<<endl;
string filecontent;
do
{
cout << "Choice? "<< endl;
cin >> choice5;
cin.clear();
cin.ignore(10000,'n');
}while(!cin.good());
switch(choice5)
{
case 1:
{
cout<<"What file would you like to load? ";
cin>>filename;
cout<<endl;
next = state_loadgamemenu;
}
break;
case 2:
{
inFS.open(filename.c_str());
if(!inFS.is_open())
{
next = state_savegamemenu;
break;
}
else
{
while(!inFS.eof())
{
inFS >> filecontent;
if(inFS.good())
{
cout << filecontent << endl;
}
}
}
inFS.close();
next = state_loadgamemenu;
}
break;
case 3:
next = state_Mmenu;
break;
default:
cout << "Bad Input!"<<endl;
next = state_loadgamemenu;
break;
}
cout <<endl;
return next;
}
我遇到的错误是对StatesaveGameMenu((和StateloAdgamemenu((的不确定的引用。对于我的知识范围,这样的链接器错误与该程序无法找到有关函数的定义有关,但是我显然已经实施了它们,所以我对为什么会发生这种情况以及任何帮助我感到非常困惑将不胜感激。
在保存游戏和加载游戏中,您忘了这样做,因此与呼叫不匹配
state statesavegamemenu(string fname, string lname, string filename,
ofstream outFS)
{
to
state statesavegamemenu(string fname, string lname, string filename,
ofstream& outFS)
{
与其他功能相同,但ifstream而不是ifstream&amp;
相关文章:
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 列表 iter 不取消引用 使用列表进行插入排序
- 不确定如何装饰我的C++库代码以在 C 中使用
- C++功能泄漏内存,我是C++新手,不确定如何解决
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 为什么我不能引用指向实例化对象的函数的指针?
- 我不确定如何引用此神经网络训练方法中的权重
- makefile对我的名称空间对象/函数/构造函数的不确定引用
- liberial对符号的不确定引用
- 为每个抽象函数定义主体后,对VTable的不确定引用
- 即使我的函数全部定义,也会在C 中获得不确定的引用
- 使用C和C 一起使用函数错误的不确定引用
- C 对CODE :: morsecode()的不确定引用和对Code :: AlphaCode()的未定义引用
- 在代码块中的SDL_SHOWSIMPLEMESSAGEBOX中,令人困惑的错误,不确定的引用和未定义的引用
- 在初始评估列表中引用类成员是不确定的行为吗?
- 对班级卡的不确定引用
- Arduino不确定对操作员的引用
- 在标题文件中列出的对象,但在CPP文件中却不确定引用
- 如果没有使用使用代码的链接,则对G 中的静态常规成员的不确定引用
- 我不确定为什么我会收到 NULL 指针取消引用错误