2014-06-05 31 views
1

就像标题所说,我认为我的一个包含问题。包括程序上的图形界面

我很熟悉,我的老师给了我一个解决方案,创建一个名为EZ-Draw的视觉界面(由他自己编码)。

但地方在我的代码有一个问题,因为我的编译器告诉我这种风格的许多错误:

|364|undefined reference to `[email protected]'| 
|559|undefined reference to `[email protected]'| 
... 

我的代码:

interpreteur.hpp

#ifndef INTERPRETEUR_HPP_INCLUDED 
#define INTERPRETEUR_HPP_INCLUDED 
#include <sstream> 
#include <map> 
#include <math.h> 
#include "Pile_Template.hpp" 
#include "ez-draw++.h" 

#define PI 3.14159265 

class Interpreteur { 
private: 
    void (Interpreteur::*ptr)(); 
    EZWindow myWindow; 
    Pile<double> pile; 
    Pile<string> pilestr; 
    bool run; 
public: 
    map<string,void(Interpreteur::*)()> myMap; 
    Interpreteur(); 
    ~Interpreteur(); 
    inline bool getRun() {return run;}; 
    inline void setEmpilerPile(double nombre) {pile.empiler(nombre);}; 
    template <typename T> 
     string itos(T nombre) // convertit un double en string 
     { 
      ostringstream ss; 
      ss<<nombre; 
      return ss.str(); 
     } 
    void addition(); 
    void moins(); 
    void multiplie(); 
    void divise(); 
    void quit(); 
    void push(); 
    void pushstr(); 
    void pop(); 
    void popstr(); 
    void copy(); 
    void copystr(); 
    void print(); 
    void printstr(); 
    void display(); 
    void displaystr(); 
    void count(); 
    void countstr(); 
    void swap(); 
    void swapstr(); 
    void sinus(); 
    void cosinus(); 
    void tangente(); 
    void racine(); 
    void trunc(); 
    void line(); 
    void color(); 
    void drawstr(); 
    void triangle(); 
    void rectangle(); 
    void circle(); 

}; 
#endif // SOUS_PROGRAMMES_HPP_INCLUDED 

interpreteur.cpp

#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); 
} 

这里的"EZ-Draw documentation"红粉由我的老师了解ez-drawez-draw++

我不明白编译器是想告诉我

+0

您可能要编辑您的帐户说明,法语中的“étudiant”用英语拼写为“学生”。 –

回答

1

您正在使用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++不同,因为在C++中你可以重载一个函数,函数的名字本身并不能唯一地标识一个函数,所以当你编译时,编译器会在后台函数的名字中添加一些符号以使这些名称唯一(这就是[email protected]中的[email protected])。

因为你的连接预计C++函数,它将搜索[email protected],但某些文件被编译在C,并导出一个名为CreateCompatible功能,这就是为什么你会得到一个“未定义参考”:链接器告诉你它找不到某些功能的定义。

+0

好的,但是我把刚才写的代码片段放在里面:'#ifdef __cplusplus extern“C”{...} #endif' –

+0

在头文件的开始和结尾声明函数给你错误信息。 –