globale typedef definitionen:



  • HALLO.

    ich möchte gerne einige typedef für mein gesamtes c++ projekt vornehmen. das soll in etwa wie folgt aussehen (meine "Definition.h"):

    #include <vector>
    #include <algorithm>
    
    typedef std::pair <int,int>			MyPairInt;
    typedef std::pair <double,double>	MyPairDbl;
    typedef std::pair <double,int>		MyPairDblInt;
    typedef std::vector <MyPairDblInt>	MyVecDblInt;
    typedef std::vector	<MyPairInt>		MyVecPairInt;
    typedef std::vector<int>			MyVecInt;
    typedef std::pair <int,MyPairInt>	MyPair3;
    
    extern const int DIM1;
    extern const int DIM2;
    extern const int REFPOINT;
    extern const int REFPATT;
    extern const double PHI;
    

    nun meine frage: wie kann ich diese datei in mein projekt einbinden, um derartige fehlermeldungen zu vermeiden:

    error LNK2019: unresolved external symbol "bool __cdecl lower_second<struct std::pair<double,int> >(struct std::pair<double,int> const &,struct std::pair<double,int> const &)" (??lower_second@U?lower\_second@U?pair@NH@std@@@@YA_NABU?pair@NH@std@@0@Z) referenced in function "private: void \_\_thiscall cBild::GetSepara(bool,double,class std::vector,class std::allocator > > &,class std::vector,class std::allocator > > &,class std::vector >,class std::allocator > > > * const)" (?GetSepara@cBild@@AAEX\_NNAAV?vector@U?pair@NH@std@@V?pair@NH@std@@V?allocator@U?pair@NH@std@@@2@@std@@1QAV?pair@NH@std@@@2@@std@@1QAV?vector@U?pair@HU?pair@HU?pair@HH@std@@@std@@V?allocator@U?allocator@U?pair@HU?$pair@HH@std@@@std@@@2@@3@@Z) cBild_e.obj

    VIELEN DANK!
    STICK.



  • Was ist lower_second? Ist das von dir?



  • Ja. das habe ich geschrieben. was könnte damit nicht stimmen? 😕



  • stick_thai schrieb:

    Ja. das habe ich geschrieben. was stimmt damit nicht? 😕

    Das ist die Funktion, die der Linker nicht findet. Das hat IMHO mit deinen Typedefs nichts zu tun. Da das offenbar ein Template ist: Hast du die auch brav in der Headerdatei definiert?



  • Das können wir Dir auch nicht sagen, da wir bisher nicht wissen was das macht/ist. Jedenfalls beschwert sich der Linker dass er lower_second nicht findet.



  • meine Functions.h

    #include <conio.h>
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <cmath>
    
    #include <Globals.h>
    
    double	PoNe		(double);
    bool	CheckBorder (int,int);
    double	ArcTan		(double,double);
    void	AssignInter	(int[2],double,double);
    int		ConvAngle	(int,int);
    void	ClearStream	(std::stringstream &);
    int		FilterBinomial	(int,int);
    void	VecProd		(double[3],double[3],double[3]);
    
    template <typename T> bool greater_first	(const T &lhs, const T &rhs);
    template <typename T> bool greater_second	(const T &lhs, const T &rhs);
    template <typename T> bool lower_second		(const T &lhs, const T &rhs);
    

    und hier meine Functions.cpp

    double	PoNe		(double wert)
    {
    //  ...
    }
    bool	CheckBorder (int a, int b)
    {
    //  ...
    }
    double	ArcTan		(double x, double y)
    {
    //  ...
    }
    
    void	AssignInter	(int inter[4],double rad, double angle)
    {
    //  ...
    }
    int		ConvAngle	(int a,int b)
    {
    //  ...
    }
    
    void	ClearStream	(std::stringstream &filename)
    {
    //  ...
    }
    int		FilterBinomial	(int m, int n)
    {
    //  ...
    }
    
    void	VecProd		(double m[3],double n[3],double erg[3])
    {
    //  ...
    }
    
    template <typename T> bool greater_first	(const T &lhs, const T &rhs)
    {
    	return (rhs.first<lhs.first);
    }
    template <typename T> bool greater_second	(const T &lhs, const T &rhs)
    {
    	return (rhs.second<lhs.second);
    }
    template <typename T> bool lower_second		(const T &lhs, const T &rhs)
    {
    	return (rhs.second > lhs.second);
    }
    

    müsste meiner meinung nach alles stimmen, oder? denn z.B. die funktion PoNe(), die in der gleichen source datei wie lower_second auftaucht, macht keine probleme.



  • Die Definition der Templatefunktionen muss in die Headerdatei.

    Nicht, dass dieses Thema hier ungefähr jeden zweiten Tag auftaucht 😉



  • Sorry, habe ich noch nicht gewusst. aber wenn ich das umsetze, dann gibt es folgende meldungen:

    error C2995: 'bool greater_first(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool greater_second(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool lower_second(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool greater_first(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool greater_second(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool lower_second(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool greater_first(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool greater_second(const T &,const T &)' : function template has already been defined	
    error C2995: 'bool lower_second(const T &,const T &)' : function template has already been defined
    

    EDIT:
    Habs jetzt so in der Functions.h gelöst:

    #ifndef FUNCTIONS_H
    #define FUNCTIONS_H
    template <typename T> bool greater_first	(const T &lhs, const T &rhs)
    {
    	return (rhs.first<lhs.first);
    }
    template <typename T> bool greater_second	(const T &lhs, const T &rhs)
    {
    	return (rhs.second<lhs.second);
    }
    template <typename T> bool lower_second		(const T &lhs, const T &rhs)
    {
    	return (rhs.second > lhs.second);
    }
    #endif
    

    ist das ne gute idee?



  • Ich wollte gerade schreiben dass vermutlich geeignete Include-Guards fehlen, aber das hast Du scheinbar schon selbst gelöst. Ja, Include-Guards sind nie falsch 😉



  • JA. es scheint, dass sie den von mir gewünschten zweck erfüllen.

    davon mal abgesehen, dass ich mit deinem hinweis, dass "geeignete Include-Guards fehlen", nichts hätte anfangen können, da ich den begriff zuvor noch nie gehört habe 😉



  • stick_thai schrieb:

    davon mal abgesehen, dass ich mit deinem hinweis, dass "geeignete Include-Guards fehlen", nichts hätte anfangen können, da ich den begriff zuvor noch nie gehört habe 😉

    Gehört nicht, aber verwendet 😉 (Include-Guards nennt man den #ifndef X/#define X/.../#endif Block, mit dem man die Mehrfacheinbindung von Headern verhindern kann)


Anmelden zum Antworten