0

Using Visual Studio 2015, I have been trying load a table that contains floating point values for degrees converted to radians. Since the MathFunctions class is static (static functions), I am trying to initialize the map that withholds the converted radian values. But I keep getting LNK2001 unresolved symbol error when I reference the map inside the InitTables/Degree2Radians functions - Note that both the header and cpp files lie in the same project under the same folder "Utilities"

Declarations (MathFunctions.h)

 #pragma once
 #ifndef MATHFUNCTIONS_H
 #define MATHFUNCTIONS_H
 #define _USE_MATH_DEFINES
 #include <math.h>
 #include <map>
 #include <fstream>
 using namespace std;

namespace LookupTables
{
    class MathFunctions
    {
      private:
        static map<short, float>Degree2RadiansTable;

      public:
        static void InitTables();
        static float Degree2Radians(short angleInDegrees);      
};
}
#endif

While Definitions (MathFunctions.cpp) are as follows

namespace LookupTables
{
    void MathFunctions::InitTables()
    {
        // Load degree2radians table
        short degrees = 0;
        float radians = 0;
        ifstream infile("..\Tables\Degree2Radians.txt");
        if (infile.good() && infile.is_open())
        {
                while (infile >> degrees && infile >>radians) 
                {
                    MathFunctions::Degree2RadiansTable.insert({ degrees,radians });
                }
        }
        infile.close();     
    }

    float MathFunctions::Degree2Radians(short angleInDegrees)
    {
        return MathFunctions::Degree2RadiansTable[angleInDegrees];
    }
}

I am not sure what is wrong.

Wajih
  • 793
  • 3
  • 14
  • 31

0 Answers0