LNK2019 VS2015 error



  • Mistake

    LNK2019 reference to an unauthorized external symbol "public: __thiscall MassClass:~MassClass(void)? MassClass@H@QAE@XZ) function _main DinamMass D:\C+\Source.obj 1

    I bet you add all the files on your own, complimented on your own, danced with the booth, but nothing worked.

    MassClass.h

    #pragma once
    

    template <typename T>
    class MassClass
    {
    private:
    int size;
    T *ptr;
    void boundaries(int n,MassClass &m);
    void initsial(MassClass &m);
    public:
    MassClass(int n = 0);
    void copy(MassClass &m1, MassClass &m2);
    void addrozmir(MassClass &m1, int n);
    void print(void);
    ~MassClass();
    };

    MassClass.cpp

    #include "MassClass.h"
    #include "math.h"

    template <typename T>
    MassClass<T>::MassClass(int n)
    {
    if (n > 0)
    size = n;
    ptr = new T[size];
    for (int i = 0; i < size i++)
    {
    ptr[i] = 0;
    }
    else
    {
    size = abs(n);
    ptr = new T[size];
    for (int i = 0; i < size i++)
    {
    ptr[i] = 0;
    }
    }
    }

    template <typename T>
    MassClass<T>::~MassClass()
    {
    delegate[] ptr;
    }

    template <typename T>
    void MassClass<T>::copy(MassClass &m1, MassClass &m2)
    {
    delegate[] m1.ptr;
    m1.size = m2.size;
    m1.ptr = new T[m1.size];
    for (int i = 0, i < m2.size, i++)
    {
    m1.ptr[i] = m2.ptr[i];
    }
    }

    template <typename T>
    void MassClass<T>::boundaries(int n, MassClass<T> &m1)
    {
    if (m1.size < n)
    {
    std::cout << "Vihod za granitsi";
    }
    }

    template <typename T>
    void MassClass<T>::addrozmir(MassClass<T> &m1, int n)
    {
    delete[] m1.ptr;
    m1.ptr = new T[n];
    initsial(m1);
    }

    template <typename T>
    void MassClass<T>::initsial(MassClass<T> &m1)
    {
    for (int i = 0, i < m1.size, int i++)
    {
    m1.ptr[i] = 0;
    }
    }

    template <typename T>
    void MassClass<T>::print(void)
    {
    for (int i = 0, i < size, i++)
    {
    cout << i << " " << ptr[i];
    }
    }

    Source.cpp

    #include <iostream>
    #include <conio.h>
    #include "math.h"
    #include "MassClass.h"

    using namespace std;

    void main(void)
    {
    MassClass<int> m1(10);
    m1.print();
    _getch();
    }

    Mistakes

    Серьезность Код Описание    Проект  Файл    Строка  Состояние подавления
    Ошибка LNK1120 неразрешенных внешних элементов: 3 DinamMass D:\С++\Mass\DinamMass\Debug\DinamMass.exe 1
    Ошибка LNK2019 ссылка на неразрешенный внешний символ "public: void __thiscall MassClass<int>::print(void)" (?print@?$MassClass@H@@QAEXXZ) в функции _main DinamMass D:\С++\Source.obj 1
    Ошибка LNK2019 ссылка на неразрешенный внешний символ "public: __thiscall MassClass<int>::MassClass<int>(int)" (??0?$MassClass@H@@QAE@H@Z) в функции _main DinamMass D:\С++\Source.obj 1
    Ошибка LNK2019 ссылка на неразрешенный внешний символ "public: __thiscall MassClass<int>::~MassClass<int>(void)" (??1?$MassClass@H@@QAE@XZ) в функции _main DinamMass D:\С++\Mass\Source.obj 1



  • The definitions of the template should be in the headline files. Look, in the compilation. MassClass.cpp I don't know how the compilator knows.that you will install a class with a type int? He doesn't know, and he doesn't do anything. A in the compilation Source.cpp He knows, but he can't do anything because he doesn't have a code.

    That's it. ♪ ♪

    P.S. By the way, you've got a lot of mistakes. MassClass.cppBut since the compiler doesn't install anything, he just doesn't notice them. ♪ ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2