我有三個參數構造函數的恕我直言很奇怪的問題,當我嘗試運行程序時,Visual Studio只顯示了一個錯誤:「'Sort.HeapSort'不包含構造函數,它需要3個參數112 35「。C#構造函數的奇怪問題
namespace Sort
{
class HeapSort
{
private int[] A;
private int heapSize;
private int min;
private int max;
Random myRandom = new Random();
HeapSort(int size, int min1, int max1) //this is the three argument constructor.
{
heapSize = size - 1;
min = min1;
max = max1;
A = new int[size];
}
}
class Program
{
static void Main(string[] args)
{
int size = 30;
int min = 0;
int max = 100;
HeapSort myHeapSort = new HeapSort(size,min,max); //In this line is the bug
}
}
}
你有沒有嘗試過公開構造函數? – 2010-11-17 16:36:06
你能刪除無用的線路嗎?:) – ykatchou 2010-11-17 16:36:21
也許你應該用適當的訪問修飾符來修飾你的類。公共,私人,保護等。 – StingyJack 2010-11-17 16:36:37