VC ++错误LNK2019 LNK1120

时间:2012-11-12 18:04:52

标签: visual-c++

我正在建立一个使用ICloneable的学校项目。这是一个非常直接的项目,但我似乎无法通过这个错误:

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控制台应用程序。我确信我选择了正确的应用程序。

这是给我问题的代码:

/*
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
};

1 个答案:

答案 0 :(得分:1)

你需要一个main()函数,所以链接器可以找到它。

int main(array<System::String ^> ^args)
{ 
    TestCloning::main();
    return 0;
}