Ошибка LNK 2019, неразрешенный внешний символ, забавно то, что работал прошлой ночью без ошибок, сохраненный пошел спать, работал и получил эту ошибку

В конце концов я хочу переместить эти функции и класс в файл cpp. Но хочу убедиться, что программа хотя бы запускается. И да, я проверил предыдущие вопросы, касающиеся LNK2019 ошибки, но безрезультатно. это копия ошибки, которую я получаю

Ошибка 12, ошибка LNK2019: неразрешенный внешний символ "public: __thiscall MathHelper::~MathHelper(void)" (??1?$MathHelper@N@@QAE@XZ), на который есть ссылка в функции _wmain

а второй, в основном, получая эти два для каждого типа данных, т.е. double, short, long, float)

Ошибка 11, ошибка LNK2019: неразрешенный внешний символ "public: __thiscall MathHelper::MathHelper(void)" (??0?$MathHelper@N@@QAE@XZ), на который есть ссылка в функции _wmain C:\Users\Jalin\Desktop\visual\ConsoleApplication27\ConsoleApplication27\ConsoleApplication27.obj ConsoleApplication27

Вот код:

 ConsoleApplication27.cpp : Defines the entry point for the console application.
 //

#include "stdafx.h"
#include<iostream>
#include<random>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <tchar.h>
 //#include "MathHelper.h"

using std::cout;
using std::cin;
using std::endl;

template <class T>
class MathHelper
{
public:
T sum1(T x[], int y);


T average(T x, int y);

T highest(T x[], int y);


T lowest(T x[], int y);


T range(T x, T y);

T wantedgrade(T x, T y, int z);


T standev(T x, T a[], int y);


T fact(T x[], T average1, int count);

MathHelper();
~MathHelper();

 };


 //template <typename> T values()
  int _tmain(int argc, _TCHAR* argv[])
 {
  static std::mt19937 rng;
  rng.seed(std::random_device()());
  std::uniform_int_distribution<std::mt19937::result_type> dist6(1, 100);

short arrayshort[10];
double arraydouble[10];
long arraylong[10];
float arrayfloat[10];
int count = 0;
int count1 = 10;
short desiredgrade;
MathHelper<short> gshort;
MathHelper<double> gdouble;
MathHelper<long> glong;
MathHelper<float> gfloat;




for (int count = 0; count < 10; count++)
{
    arrayshort[count] = dist6(rng);
}
for (int count = 0; count < 10; count++)
{
    arraydouble[count] = dist6(rng);
}
for (int count = 0; count < 10; count++)
{
    arraylong[count] = dist6(rng);
}
for (int count = 0; count < 10; count++)
{
    arrayfloat[count] = dist6(rng);
}
cout << " the numbers entered for the following arrays are:\n";
cout << "short array: ";
for (int count = 0; count < 10; count++)
{
    cout << arrayshort[count] << " ";
}

cout << endl;
cout << "double array: ";
for (int count = 0; count < 10; count++)
{
    cout <<  arraydouble[count] << " ";
}

cout << endl;
cout << "long array: ";
for (int count = 0; count < 10; count++)
{
    cout <<  arraylong[count] << " ";
}

cout << endl;
cout << "float array: ";
for (int count = 0; count < 10; count++)
{
    cout << arrayfloat[count] << " ";
}

cout << endl;
cout << "The sum of all grades for the short array entered is " << gshort.sum1(arrayshort, count1) << endl;
cout << "The sum of all grades for the double array entered is " << gdouble.sum1(arraydouble, count1) << endl;
cout << "The sum of all grades for the long array entered is " << glong.sum1(arraylong, count1) << endl;
cout << "The sum of all grades for the float array entered is  " << gfloat.sum1(arrayfloat, count1) << endl;

short shortsum = gshort.sum1(arrayshort, count1);
double doublesum = gdouble.sum1(arraydouble, count1);
long longsum = glong.sum1(arraylong, count1);
float floatsum = gfloat.sum1(arrayfloat, count1);

cout << endl;
cout << "The average of all grades for the short array entered is " << gshort.average(shortsum, count1) << endl;
cout << "The average of all grades for the double array entered is " << gdouble.average(doublesum, count1) << endl;
cout << "The average of all grades for the long array entered is " << glong.average(longsum, count1) << endl;
cout << "The average of all grades for the float array entered is  " << gfloat.average(floatsum, count1) << endl;

short shortaverage = gshort.average(shortsum, count1);
double doubleaverage = gdouble.average(doublesum, count1);
long longaverage = glong.average(longsum, count1);
float floataverage = gfloat.average(floatsum, count1);

cout << endl;
cout << "The Highest number in the short array entered in: " << gshort.highest(arrayshort, count1);
cout << "The Highest number in the double array entered in: " << gdouble.highest(arraydouble, count1);
cout << "The Highest number in the long array entered in: " << glong.highest(arraylong, count1);
cout << "The Highest number in the float array entered in: " << gfloat.highest(arrayfloat, count1);

cout << endl;
cout << "The lowest number in the short array entered in: " << gshort.lowest(arrayshort, count1) << endl;
cout << "The Lowest number in the double array entered in: " << gdouble.lowest(arraydouble, count1) << endl;
cout << "The Lowest number in the long array entered in: " << glong.lowest(arraylong, count1) << endl;
cout << "The Lowest number in the float array entered in: " << gfloat.lowest(arrayfloat, count1) << endl;

short hshort = gshort.highest(arrayshort, count1);
short lshort = gshort.lowest(arrayshort, count1);

double hdouble = gdouble.highest(arraydouble, count1);
double ldouble = gdouble.lowest(arraydouble, count1);

long hlong = glong.highest(arraylong, count1);
long llong = glong.lowest(arraylong, count1);

float hfloat = gfloat.highest(arrayfloat, count1);
float lfloat = gfloat.lowest(arrayfloat, count1);

cout << endl;
cout << "The range between the highest and lowest value in the short array is: " << gshort.range(hshort, lshort)<<endl;
cout << "The range between the highest and lowest value in the double array is: " << gdouble.range(hdouble, ldouble) << endl;
cout << "The range between the highest and lowest value in the long array is: " << glong.range(hlong, llong) << endl;
cout << "The range between the highest and lowest value in the float array is: " << gfloat.range(hfloat, lfloat) << endl;

cout << "enter in your desired grade for the short array: ";
cin >> desiredgrade;
cout << "The grade that you need to make to match you desired average is " << gshort.wantedgrade(shortsum, desiredgrade, count1) << endl;

cout << "enter in your desired grade for the double array: ";
cin >> desiredgrade;
cout << "The grade that you need to make to match you desired average is " << gdouble.wantedgrade(doublesum, desiredgrade, count1) << endl;

cout << "enter in your desired grade for the long array: ";
cin >> desiredgrade;
cout << "The grade that you need to make to match you desired average is " << glong.wantedgrade(longsum, desiredgrade, count1) << endl;

cout << "enter in your desired grade for the float array: ";
cin >> desiredgrade;
cout << "The grade that you need to make to match you desired average is " << gfloat.wantedgrade(floatsum, desiredgrade, count1) << endl;

cout << "The standard deviation for the short array is: " << gshort.standev(shortaverage, arrayshort, count1)<<endl;
cout << "The standard deviation for the double array is: " << gdouble.standev(doubleaverage, arraydouble, count1) << endl;
cout << "The standard deviation for the long array is: " << glong.standev(longaverage, arraylong, count1) << endl;
cout << "The standard deviation for the float array is: " << gfloat.standev(floataverage, arrayfloat, count1) << endl;

cout << "the Factorial for the short array is:  " << gshort.fact(arrayshort, shortaverage, count1)<<endl;
cout << "the Factorial for the double array is:  " << gdouble.fact(arraydouble, doubleaverage, count1) << endl;
cout << "the Factorial for the long array is:  " << glong.fact(arraylong, longaverage, count1) << endl;
cout << "the Factorial for the float array is:  " << gfloat.fact(arrayfloat, floataverage, count1) << endl;
return 0;
  }

    template <class T>
    T MathHelper<T>::sum1(T x[], int y)
   {



 T sum = 0;
     for (int i = 0; i < y; i++)
     {


         sum += x[i];


     }
     return sum;
 }
 template <class T>
 T MathHelper<T>::average(T x, int y)
 {
     T average = x / y;


     return average;
}
 template <class T>
 T MathHelper<T>::highest(T x[], int y)
 {
    T highest = 0;
    for (int i = 0; i <= y; i++)
    {
        if (x[i]>highest)
            highest = x[i];
    }
    return highest;

 }
template <class T>
T MathHelper<T>::lowest(T x[], int y)
{
    T lowest = *std::min_element(x,
        x + y);
    return lowest;
}
template <class T>
T MathHelper<T>::range(T x, T y)
{
    T range = x - y;
    return range;
}
template <class T>
T MathHelper<T>::wantedgrade(T x, T y, int z)
{

    T futuregrade = (z + 1) * y;
    T needtomake = futuregrade - x;
    if (needtomake > 100 || needtomake < 0)
    {


        return 0;
    }
    else
        return needtomake;

}
template <class T>
T MathHelper<T>::standev(T x, T a[], int y)
{
    T sum = 0;
    T numer = 0;

    for (int i = 0; i < y; i++)
    {
        sum = pow((a[i] - x), 2);
        numer += sum;

    }
    T standd = sqrt(numer / y);

return standd;

}
template <class T>
T MathHelper<T>::fact(T x[], T average1, int count)
{
    T averagex = average1;
    T highestx = x[0];
    T lowfact = highestx;
    T facto = 0;

for (int j = 0; j < count; j++)
{
        int factor = 0;
        factor = x[j];
        for (int i = factor - 1; i>0; i--)
        {
            facto = factor*i;
        }

    if (facto>averagex && x[j] <= highestx)
        {
            lowfact = x[j];
        }

    }

return lowfact;

}

0 ответов

Другие вопросы по тегам