I have been getting this error: ‘unresolved external symbol main referenced in function __tmainCRTStartup’ when I attempt to compile my c++ console application. I have done some searching and all I could find was changing my ‘linker’ from windows to console or vice versa. This didn’t work, I even tried creating a new console application.
I am unsure as to what is causing this, is it possible that template <typename T> is causing confusion as it appears in both files? Any help here would be much appreciated.
Code Below:
Main.cpp:
#include <iostream>
#include "tools.h"
using namespace tools;
template <typename T>
int main()
{
T input1;
T input2;
std::cout << "Enter in 1st number: " << endl;
std::cin >> input1;
std::cout << "Enter in 2nd number: " << endl;
std::cin >> input2;
std::cout << "num1 - num2 = [" << numberDifference(input1, input2) << "]" << endl;
getchar();
getchar();
return 0;
}
Tools.h:
#include <iostream>
namespace tools
{
template <typename T>
T numberDifference(T num1, T num2)
{
if(num1 > num2)
return num1 - num2;
else
return num2 - num1;
}
};
Remove the
templatedefinition for yourmainfunction.Or at least call it from a proper
mainfunction.e.g.