![](/img/trans.png)
[英]error : unresolved external symbol _main referenced in function ___tmaincrtstartup
[英]unresolved external symbol _main referenced in function ___tmainCRTStartup
我一直在收到以下錯誤消息:當我嘗試編譯c ++控制台應用程序時,“函數_ _tmainCRTStartup中引用了未解析的外部符號main ”。 我進行了一些搜索,發現所有的更改都是將“鏈接器”從Windows更改為控制台,反之亦然。 這沒有用,我什至嘗試創建一個新的控制台應用程序。
我不確定是什么原因引起的, template <typename T>
是否有可能引起混淆,因為它出現在兩個文件中? 在這里的任何幫助將不勝感激。
下面的代碼:
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;
}
};
刪除main
功能的template
定義。
或者至少從適當的main
函數調用它。
例如
template< typename T >
int templated_main( int c, char** argv )
{
// What was in your original main function....
}
int main( int c, char** argv )
{
return templated_main<int>( c, argv );
}
在main之前刪除template <typename T>
。 這將使main
成為模板功能。
並改變T input1; T input2;
T input1; T input2;
到某些特定類型,例如int
或float
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.