1

I have IMHO very strange problem with three-argument constructor , When I try to run the program visual studio shows me only one bug: " 'Sort.HeapSort' does not contain a constructor that takes 3 arguments 112 35" .

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
        }
    }
}
5
  • 1
    Have you tried declaring the constructor public? Commented Nov 17, 2010 at 16:36
  • Could you remove useless lines plz :) Commented Nov 17, 2010 at 16:36
  • perhaps you should decorate your classes with the proper access modifiers. Public, Private, protected, etc. Commented Nov 17, 2010 at 16:36
  • Could you fix the odd formating? (Moglbys naprawiac dziwny format?) Commented Nov 17, 2010 at 16:37
  • 8 Answers in a blink of a sloth eye :pLooks like everyone is in the starting block Commented Nov 17, 2010 at 16:40

8 Answers 8

9

Your constructor is declared private, since you omitted an access specifier. Add the public keyword prior to the constructor definition.

Sign up to request clarification or add additional context in comments.

1 Comment

You should check the box beneath the update/down vote buttons to accept his answer then instead of editing the title to mark it solved.
3

You need to specify your constructor as public, thusly:

public HeapSort(int size, int min1, int max1) 

The compiler allows you to omit the accessibility specifier and defaults to private. Bit of a syntactic sugar gotcha IMO that I wish would be done away with.

So, since you have a private constructor, your client code does not "see" it and the compiler tries to call the public constructor which naturally results in the error you're seeing.

Comments

2

Your constructor isn't public, it's private (you didn't include any modifiers so it defaults to private) therefore the calling code can't "see" it.

Change:

HeapSort(int size, int min1, int max1)

To:

public HeapSort(int size, int min1, int max1)

Comments

1

You need to add public to your constructor, otherwise it's considered private, and therefore inaccessible from within your Main().

Comments

1

The constructor with three params has no accessibility modifier on it and so defaults to private.

Change the declaration to public HeapSort(int size, int min1, int max1) and you'll be good-to-go.

Comments

0

It looks like you are missing 'public' keyword before constructor.

Comments

0

Make your constructor public !

Comments

0

Your constructor is private. It needs to be public.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.