2012-11-12 85 views
0

我正在構建一個使用ICloneable的學校項目。這是一個非常簡單的項目,但我似乎無法能夠獲得通過此錯誤:VC++錯誤LNK 2019 LNK 1120

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

您將需要一個main()函數該集體因此鏈接可以找到它。

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

感謝漢斯。當然,你是對的。 :) – deadEddie