C++ 在程序中包括图形界面
就像标题所说的,我想我的一个收录有问题 我是一名学生,我的老师给了我一个解决方案来创建一个名为C++ 在程序中包括图形界面,c++,graphics,compiler-errors,include,C++,Graphics,Compiler Errors,Include,就像标题所说的,我想我的一个收录有问题 我是一名学生,我的老师给了我一个解决方案来创建一个名为EZ-Draw的可视化界面(由他自己编写) 但在我的代码中有一个问题,因为我的编译器告诉我许多这种类型的错误: |364|undefined reference to `CreateCompatibleDC@4'| |559|undefined reference to `SelectObject@8'| ... 我的代码: 水电站 #如果包括水电站口译员# #定义包括的水电站 #包括 #包括 #包括
EZ-Draw
的可视化界面(由他自己编写)
但在我的代码中有一个问题,因为我的编译器告诉我许多这种类型的错误:
|364|undefined reference to `CreateCompatibleDC@4'|
|559|undefined reference to `SelectObject@8'|
...
我的代码:
水电站
#如果包括水电站口译员#
#定义包括的水电站
#包括
#包括
#包括
#包括“Pile_Template.hpp”
#包括“ez draw++.h”
#定义PI 3.14159265
班主任{
私人:
无效(译员::*ptr)();
ezwindowmywindow;
桩;
桩柱;
布尔润;
公众:
地图我的地图;
解释器();
~r();
内联bool getRun(){return run;};
内联void setempilerfile(双名){pile.empiler(名);};
模板
字符串itos(T nombre)//转换为双en字符串
{
ostringstream ss;
ssi;
打桩机(一);
}
void解释器:pushstr()
{
串链;
查尔默德;
cin>>梅德;
如果(merde==“”)
{
getline(cin,chaine,“”);
临时工(链);
}
其他的
{
反刍动物(merde);
CERP RP< >你使用C++的C函数,为了工作,你需要明确地告诉编译器C函数。C++中使用的C头文件应该包含C++中使用的那些行:
#ifdef __cplusplus
extern "C" {
#endif
//The header file which declares the functions which are not linked correctly here
#ifdef __cplusplus
}
#endif
一点解释:
C和C++的函数“名称MangLin”是不同的,因为在C++中你可以重载一个函数,函数的名称不能单独标识一个函数,所以编译器编译时在后台的函数名中添加一些符号,使这些名称唯一。(这就是DC@4inCreateCompatibleDC@4
)。
因为链接器期望C++函数,所以它搜索<代码>CreateCompatibleDC@4
,但是您的一些文件是用C语言编译的,并导出一个名为CreateCompatible
的函数,这就是为什么您会得到一个“未定义的引用”:链接器告诉您它找不到某些函数的定义。好的,但我将您刚刚编写的代码片段放在了:\ifdef\uucplusplus extern“C”{…}#endif
在头文件的开头和结尾,声明向您发送错误消息的函数。您可能需要编辑您的帐户说明,法语中的“étudiant”在英语中拼写为“student”。
#include "interpreteur.hpp"
#include <sstream>
#include <map>
#include <math.h>
#include <string>
using namespace std;
void Interpreteur::addition()
{
pile.empiler(pile.depiler()+pile.depiler());
}
void Interpreteur::moins()
{
double nombre=pile.depiler();
nombre=pile.depiler()-nombre;
pile.empiler(nombre);
}
void Interpreteur::multiplie()
{
pile.empiler(pile.depiler()*pile.depiler());
}
void Interpreteur::divise()
{
double nombre=pile.depiler();
nombre=pile.depiler()/nombre;
pile.empiler(nombre);
}
void Interpreteur::quit()
{
run=false;
}
void Interpreteur::push()
{
double i;
cin>>i;
pile.empiler(i);
}
void Interpreteur::pushstr()
{
string chaine;
char merde;
cin>>merde;
if(merde=='"')
{
getline(cin,chaine,'"');
pilestr.empiler(chaine);
}
else
{
cin.putback(merde);
cerr<<"mauvaise chaine de caractères"<<endl;
}
}
void Interpreteur::pop()
{
pile.depiler();
}
void Interpreteur::popstr()
{
pilestr.depiler();
}
void Interpreteur::copy()
{
int i=pile.depiler();
pile.empiler(pile[pile.getSommet()-i]);
}
void Interpreteur::copystr()
{
int i=pile.depiler();
pilestr.empiler(pilestr[pile.getSommet()-i]);
}
void Interpreteur::print()
{
cout<<pile.depiler()<<endl;
}
void Interpreteur::printstr()
{
cout<<pilestr.depiler()<<endl;
}
void Interpreteur::display()
{
pile.afficher(cout);
}
void Interpreteur::displaystr()
{
pilestr.afficher(cout);
}
void Interpreteur::count()
{
pile.empiler(pile.getSommet());
}
void Interpreteur::countstr()
{
pilestr.empiler(itos(pilestr.getSommet()));
}
void Interpreteur::swap()
{
double first=pile.depiler();
double second=pile.depiler();
pile.empiler(first);
pile.empiler(second);
}
void Interpreteur::swapstr()
{
string first=pilestr.depiler();
string second=pilestr.depiler();
pilestr.empiler(first);
pilestr.empiler(second);
}
void Interpreteur::sinus()
{
pile.empiler(sin(pile.depiler()*PI/180));
}
void Interpreteur::cosinus()
{
pile.empiler(cos(pile.depiler()*PI/180));
}
void Interpreteur::tangente()
{
pile.empiler(tan(pile.depiler()*PI/180));
}
void Interpreteur::racine()
{
pile.empiler(sqrt(pile.depiler()));
}
void Interpreteur::trunc()
{
int x=pile.depiler();
pile.empiler(x);
}
void Interpreteur::line()
{
int y2=pile.depiler();
int x2=pile.depiler();
int y1=pile.depiler();
int x1=pile.depiler();
myWindow.drawLine(x1,y1,x2,y2);
}
void Interpreteur::color()
{
int couleur=pile.depiler();
switch(couleur)
{
case 1:{myWindow.setColor(ez_black);break;}
case 2:{myWindow.setColor(ez_red);break;}
case 3:{myWindow.setColor(ez_green);break;}
case 4:{myWindow.setColor(ez_blue);break;}
case 5:{myWindow.setColor(ez_cyan);break;}
case 6:{myWindow.setColor(ez_magenta);break;}
case 7:{myWindow.setColor(ez_yellow);break;}
//pourquoi que on a pas fait le gris ? ez_grey
default:{pile.empiler(couleur); cerr<<"couleur inconnue"<<endl; break;}
}
// COULEUR : ez_black, ez_white, ez_grey, ez_red, ez_green, ez_blue,ez_yellow, ez_cyan, ez_magenta
}
void Interpreteur::drawstr()
{
string str=pilestr.depiler();
int y1=pile.depiler();
int x1=pile.depiler();
myWindow.drawText(EZ_MC,x1,y1,str);
}
void Interpreteur::triangle()
{
int y3=pile.depiler();
int x3=pile.depiler();
int y2=pile.depiler();
int x2=pile.depiler();
int y1=pile.depiler();
int x1=pile.depiler();
myWindow.drawTriangle(x1,y1,x2,y2,x3,y3);
}
void Interpreteur::rectangle()
{
int y2=pile.depiler();
int x2=pile.depiler();
int y1=pile.depiler();
int x1=pile.depiler();
myWindow.drawRectangle(x1,y1,x2,y2);
}
void Interpreteur::circle()
{
int y2=pile.depiler();
int x2=pile.depiler();
int y1=pile.depiler();
int x1=pile.depiler();
myWindow.drawCircle(x1,y1,x2,y2);
}
Interpreteur::Interpreteur()
{
run=true;
myMap["+"]=&Interpreteur::addition;
myMap["-"]=&Interpreteur::moins;
myMap["*"]=&Interpreteur::multiplie;
myMap["/"]=&Interpreteur::divise;
myMap["exit"]=&Interpreteur::quit;
myMap["push"]=&Interpreteur::push;
myMap["pushstr"]=&Interpreteur::pushstr;
myMap["pop"]=&Interpreteur::pop;
myMap["popstr"]=&Interpreteur::popstr;
myMap["copy"]=&Interpreteur::copy;
myMap["copystr"]=&Interpreteur::copystr;
myMap["print"]=&Interpreteur::print;
myMap["printstr"]=&Interpreteur::printstr;
myMap["display"]=&Interpreteur::display;
myMap["displaystr"]=&Interpreteur::displaystr;
myMap["count"]=&Interpreteur::count;
myMap["countstr"]=&Interpreteur::countstr;
myMap["swap"]=&Interpreteur::swap;
myMap["swapstr"]=&Interpreteur::swapstr;
myMap["sin"]=&Interpreteur::sinus;
myMap["cos"]=&Interpreteur::cosinus;
myMap["tan"]=&Interpreteur::tangente;
myMap["sqrt"]=&Interpreteur::racine;
myMap["trunc"]=&Interpreteur::trunc;
myMap["line"]=&Interpreteur::line;
myMap["color"]=&Interpreteur::color;
myMap["drawstr"]=&Interpreteur::drawstr;
myMap["triangle"]=&Interpreteur::triangle;
myMap["rectangle"]=&Interpreteur::rectangle;
myMap["circle"]=&Interpreteur::circle;
}
Interpreteur::~Interpreteur()
{
map<string, void (Interpreteur::*)()>::iterator it;
myMap.erase(it);
}
#ifdef __cplusplus
extern "C" {
#endif
//The header file which declares the functions which are not linked correctly here
#ifdef __cplusplus
}
#endif