首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VC++errors LNK 2019 LNK 1120

VC++errors LNK 2019 LNK 1120
EN

Stack Overflow用户
提问于 2012-11-13 02:04:52
回答 1查看 183关注 0票数 0

我正在构建一个使用ICloneable的学校项目。这是一个非常简单的项目,但我似乎不能通过这个错误:

代码语言:javascript
复制
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in   function ___tmainCRTStartup
1>C:\Users\Ed\Documents\Visual Studio 2012\School_Projects\Cpp   Programs\CppInterfaceProgramming\Debug\CppInterfaceProgramming.exe : fatal error LNK1120: 1   unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 

使用VS2012将该项目设置为CLR控制台应用程序。我确信我选择了正确的应用程序。

这是给我带来问题的代码:

代码语言:javascript
复制
/*
TestCloning class provides for testing of Circle and Square classes

*/
#include "stdafx.h"
#include "Square.h"
#include "Circle.h"

using namespace System;

ref class TestCloning
{
private: static ConsoleKeyInfo^ cki;
     static Object^ Copy (ICloneable^ o)
     {
         Object^ newObject = o->Clone();
         return newObject;
     }

     static void main()
     {
         while (true)
         {
             copyOrExit();
             if (cki->ToString() == "S")
             {
                 displayAndCopySquare();
             }
             else if (cki->ToString() == "C")
             {
                 displayAndCopyCircle();
             }
             else if (cki->Key == ConsoleKey::Escape)
             {
                 Environment::Exit(0);
             }
         }// while
     } // main

     // provide prompt for user to copy object or exit
     static void copyOrExit()
     {
         Console::WriteLine(L"Press the Escape key to exit, S to display and copy a Square object, " +
             "or C to display and copy a Circle object. ");
         cki = Console::ReadKey(true);
         Console::WriteLine(L"\n");
     } // end copyOrExit method

     // method to display and copy features of a square based on user input
     static void displayAndCopySquare()
     {
         String^ userInput;
         bool isNum;
         double sideLength = 0;

         while (true)
         {
             Console::WriteLine(L"Please enter a number representing the length of one side of a squareto "+
                 "examine and copy...");
             userInput = Console::ReadLine();
             isNum = double::TryParse(userInput, sideLength);

             if (isNum)
             {
                 sideLength = double::Parse(userInput);
                 break;
             }
             else
             {
                 Console::WriteLine(L"The value you entered is not a qualified value.  Please try again...");
                 Console::WriteLine("");
             }
         }// while (true)

         // create Square object and display
         Square^ mySquare = gcnew Square(sideLength);

         Console::WriteLine("The length of one side of this square is " + mySquare->Side);
         Console::WriteLine("The perimeter of this square is " + mySquare->Perimeter);
         Console::WriteLine("The area of this square is " + mySquare->Perimeter);

         // clone square to new object and display
         ICloneable^ clonedSquare = mySquare;
         Square^ newSquare = (Square^)Copy(clonedSquare);
         Console::WriteLine(L"The length of one side of the square clone is " + newSquare->Side);
         Console::WriteLine(L"The perimeter of the square clone is " + newSquare->Perimeter);
         Console::WriteLine(L"The area of the square clone is " + newSquare->Area);
         Console::WriteLine(L"\n");

     } // end of displayAndCopySquare method

     // method to display and copy features of a circle based on user input
     static void displayAndCopyCircle()
     {
         String^ userInput;
         double radius = 0;
         bool isNum;

         while (true)
         {
             Console::WriteLine(L"Please enter an integer representing the radius of a circle to examine and copy");
             userInput = Console::ReadLine();
             isNum = double::TryParse(userInput, radius);
             if (isNum)
             {
                 radius = double::Parse(userInput);
                 break;
             }
             else
             {
                 Console::WriteLine(L"The value you entered is not a qualified value.  Please try again...");
                 Console::WriteLine(L"\n");
             }
         } // while loop

         // create circle object and display
         Circle^ myCircle = gcnew Circle(radius);
         Console::WriteLine(L"The radius of this circle is " + myCircle->Radius);
         Console::WriteLine(L"The circumference of this circle is " + myCircle->Circumference);
         Console::WriteLine(L"The area of this circle is " + myCircle->Area);

         // clone circle to new object and display
         ICloneable^ clonedCircle = myCircle;
         Circle^ newCircle = (Circle^)Copy(clonedCircle);
         Console::WriteLine(L"The radius of this circle clone is " + newCircle->Radius);
         Console::WriteLine(L"The circumference of this clircle clone is " + newCircle->Circumference);
         Console::WriteLine(L"The area of this circle clone is " + newCircle->Circumference);
         Console::WriteLine(L"\n");
     } // end displayAndCopyCircle
};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-13 02:17:39

您需要在类之外使用main()函数,以便链接器可以找到它。

代码语言:javascript
复制
int main(array<System::String ^> ^args)
{ 
    TestCloning::main();
    return 0;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13349026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档