Beiträge von Sae1962

    Das ist ja gerade der Punkt: Ich habe die Vorlagenfunktion gar nicht definiert. Ich habe sie auch gar nicht deklariert! Ich habe gar keine Funktion, sondern eine Methode, die in die Klasse hineingehört. Ich programmiere sehr ungerne prozedural. Heißt das also, dass Vorlagen-Methoden praktisch unmöglich sind? Die Deklarion der Methode muss nämlich in der Klassendatei (*.H) stattfinden, die Definition auch (*.CPP), oder?

    Hallo!

    Bin gerade an einem Projekt, das ich mit C++ unter Microsoft Visual Studio 2008 entwickele. Ich hatte im übernommenen Kode mehrere Methoden, die zahlen einlasen. Die möchte ich als Vorlagen (templates) zusammenfassen. Die Übersetzung ist OK, aber die Bindung (link) gibt Fehlermeldungen aus.

    Meine Methodendefinition:

    Header-Deklaration:
    template <class T>
    bool ReadNumber(const LPCTSTR szName, T &nValue, const T nDefValue);

    Diese Methode soll jetzt ReadFloat, ReadBool, ReadInt usw. ersetzen. Komischer Weise hat der Binder keine Freude damit. Ich scheine etwas zu übersehen. Könnt ihr mir da weiterhelfen?

    Danke!

    Definition:
    template <class T>
    bool CPSDatFile::ReadNumber(const LPCTSTR szName, T &nValue, const T nDefValue)
    {
    bool bGotValue = false;
    stlString strBuffer;
    if(ReadString(szName, strBuffer, ""))
    {
    nValue = (T)_tstof(strBuffer.c_str());
    bGotValue = true;
    }
    else
    {
    nValue = nDefValue;
    }
    return bGotValue;
    }

    Fehlermeldungen:
    1>Algorithm.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<float>(char const * const,float &,float)" (??$ReadNumber@M@CPSDatFile@@QAE_NQBDAAMM@Z)" in Funktion ""public: void __thiscall CAlgorithm::InitLevels(void)" (?InitLevels@CAlgorithm@@QAEXXZ)".
    1>Data.obj : error LNK2001: Nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<float>(char const * const,float &,float)" (??$ReadNumber@M@CPSDatFile@@QAE_NQBDAAMM@Z)".
    1>Algorithm.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<int>(char const * const,int &,int)" (??$ReadNumber@H@CPSDatFile@@QAE_NQBDAAHH@Z)" in Funktion ""public: void __thiscall CAlgorithm::InitLevels(void)" (?InitLevels@CAlgorithm@@QAEXXZ)".
    1>Data.obj : error LNK2001: Nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<int>(char const * const,int &,int)" (??$ReadNumber@H@CPSDatFile@@QAE_NQBDAAHH@Z)".
    1>ScoreDisplay.obj : error LNK2001: Nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<int>(char const * const,int &,int)" (??$ReadNumber@H@CPSDatFile@@QAE_NQBDAAHH@Z)".
    1>Algorithm.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<unsigned char>(char const * const,unsigned char &,unsigned char)" (??$ReadNumber@E@CPSDatFile@@QAE_NQBDAAEE@Z)" in Funktion ""public: void __thiscall CAlgorithm::InitLevels(void)" (?InitLevels@CAlgorithm@@QAEXXZ)".
    1>Data.obj : error LNK2001: Nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<unsigned char>(char const * const,unsigned char &,unsigned char)" (??$ReadNumber@E@CPSDatFile@@QAE_NQBDAAEE@Z)".
    1>Data.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol ""public: static class std::vector<class Coordinates,class std::allocator<class Coordinates> > & __cdecl CAlgorithm::ReadRectangle<float>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,float &,float &,float &,float &)" (??$ReadRectangle@M@CAlgorithm@@SAAAV?$vector@VCoordinates@@V?$allocator@VCoordinates@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@AAM111@Z)" in Funktion ""public: class std::vector<class Coordinates,class std::allocator<class Coordinates> > & __thiscall CData::LevelDispVect(void)" (?LevelDispVect@CData@@QAEAAV?$vector@VCoordinates@@V?$allocator@VCoordinates@@@std@@@std@@XZ)".
    1>Data.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<unsigned short>(char const * const,unsigned short &,unsigned short)" (??$ReadNumber@G@CPSDatFile@@QAE_NQBDAAGG@Z)" in Funktion ""private: void __thiscall CData::CreateShipModels(void)" (?CreateShipModels@CData@@AAEXXZ)".
    1>ScoreDisplay.obj : error LNK2001: Nicht aufgelstes externes Symbol ""public: bool __thiscall CPSDatFile::ReadNumber<unsigned short>(char const * const,unsigned short &,unsigned short)" (??$ReadNumber@G@CPSDatFile@@QAE_NQBDAAGG@Z)".
    1>ScoreDisplay.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol ""public: static class std::vector<class Coordinates,class std::allocator<class Coordinates> > & __cdecl CAlgorithm::ReadRectangle<int>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int &,int &,int &,int &)" (??$ReadRectangle@H@CAlgorithm@@SAAAV?$vector@VCoordinates@@V?$allocator@VCoordinates@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@AAH111@Z)" in Funktion ""public: int __thiscall CScoreDisplay::Setup(char const * const)" (?Setup@CScoreDisplay@@QAEHQBD@Z)".
    1>D:\Programme\CogniPlusBeta\TRAINING\VRAG\VRAGt2.exe : fatal error LNK1120: 6 nicht aufgelste externe Verweise.
    1>Das Buildprotokoll wurde unter "file://d:\Arbeit\VC2008\CogniPlus\VRAG\Win32\Debug\BuildLog.htm" gespeichert.
    1>VRAG - 12 Fehler, 1 Warnung(en)