Image

Imageoppositus wrote in Imageru_cpp

Туплю...

Раздельная компиляция шаблона: нихт ферштейн!

x.h
==========================================================
#if !defined(__X_H__)
#define __X_H__

template <typename T> class X
{
private:
    T t;

public:
    X(T val);
    T get(void) const;

};

#endif // #if !defined(__X_H__)

==========================================================

x.cpp
==========================================================
#include "x.h"

template <typename T> X<T>::X(T val)

{
    t = val;
}

template <typename T> T X<T>::get(void) const

{
    return t;
}

==========================================================

main.cpp
==========================================================
#include "x.h"

int main(void)
{

    X<int> x(10);

    int y = x.get();

    return y - 10;
}

==========================================================

Итог:

Linking...
main.obj : error LNK2019: unresolved external symbol "public: int __thiscall X<int>::get(void)const " (?get@?$X@H@@QBEHXZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: __thiscall X<int>::X<int>(int)" (??0?$X@H@@QAE@H@Z) referenced in function _main
Debug/xyz1.exe : fatal error LNK1120: 2 unresolved externals

Среда MSVC .NET 2003

Помогите, плиз!