midgitads26
midgitads26

Reputation: 19

Inconsistent accessibility errors

I am currently writing a program and have come across 2 errors which I believe are related and I am unsure how to solve. The errors read...

1)

Error 1 Inconsistent accessibility: parameter type 'ref ProgrammingAssignment2.AVLTree' is less accessible than method 'ProgrammingAssignment2.EditCountryForm.EditCountryForm(ref ProgrammingAssignment2.AVLTree, System.Windows.Forms.DataGridView)' C:\Users\Adam\documents\visual studio 2010\Projects\ProgrammingAssignment2\ProgrammingAssignment2\EditCountryForm.cs 17 16 ProgrammingAssignment2

2)

Error 2 Inconsistent accessibility: property type 'ProgrammingAssignment2.AVLTree' is less accessible than property 'ProgrammingAssignment2.EditCountryForm.stuffs' C:\Users\Adam\documents\visual studio 2010\Projects\ProgrammingAssignment2\ProgrammingAssignment2\EditCountryForm.cs 60 33 ProgrammingAssignment2

The errors in the Edit Form are as follows...

public partial class EditCountryForm : Form
{

public Country ToEdit;

public EditCountryForm(ref AVLTree<Country> newTree,DataGridView newDataGridView)
{
    this.data = newDataGridView;
    this.thing = newTree;
    InitializeComponent();
}

and...

public AVLTree<Country> thing { get {return thing;} 
        set{this.thing = value;}

my AVLTree class is...

public class AVLTree<T> : BSTree<T> where T : IComparable
{
    public new void InsertItem(T item)
    {
        insertItem(item, ref root);
    }

    public void insertItem(T item, ref Node<T> tree)
    {
        if (tree == null)
        {
            tree = new Node<T>(item);
        }

        else if (item.CompareTo(tree.Data) < 0)
        {
            insertItem(item, ref tree.Left);
        }

        else if (item.CompareTo(tree.Data) > 0)
        {
            insertItem(item, ref tree.Right);
        }

        tree.BalanceFactor = height(tree.Left) - height(tree.Right);

        if (tree.BalanceFactor <= -2)
        {
            rotateLeft(ref tree);
        }
        if (tree.BalanceFactor >= 2)
        {
            rotateRight(ref tree);
        }
    }



    //Rotate the tree to the left
    public void rotateLeft(ref Node<T> tree)
    {
        Node<T> newRoot;
        //Check the Balance factor of tree.Right before rotation

        if (tree.Right.BalanceFactor > 0)
        {
            //Recursive call on the rotateRight method

            rotateRight(ref tree.Right);
        }
        //Put newRoot to tree.Right
        newRoot = tree.Right;
        //Put tree.Right equal to newRoot.Left
        tree.Right = newRoot.Left;
        //make newRoot.Left equal to tree
        newRoot.Left = tree;
        //make tree equal the newRoot
        tree = newRoot;
    }


    public void rotateRight(ref Node<T> tree)
    {
        Node<T> newRoot;
        //check the Balance factor of tree.Right before double rotation
        if (tree.Left.BalanceFactor < 0)
        {
            //make recursive call on the rotateRight method
            rotateLeft(ref tree.Right);
        }
        //assign newRoot to tree.Right
        newRoot = tree.Left;
        //make tree.Right equal to newRoot.Left
        tree.Right = newRoot.Right;
        //make newRoot.Left equal to tree
        newRoot.Right = tree;
        //make tree equal the newRoot
        tree = newRoot;
    }


    public Country ReturnCountryInfo(Country FindRow)
    {
        Country SelectedCountry = new Country(FindRow.Name, FindRow.GdpGrowth, FindRow.Inflation, FindRow.TradeBalance, FindRow.HdiRankings, FindRow.TradePartners);
        return SelectedCountry;
    }


}

}

and my country class is...

 public class Country : IComparable
{
    // Country Properties

    public String name;
    public float gdpGrowth;
    public float inflation;
    public float tradeBalance;
    public float hdiRanking;
    public LinkedList<String> tradePartners;




    //Constructor

    public Country(String name, float gdpGrowth, float inflation, float tradeBalance, float hdiRanking, LinkedList<String> tradePartners)
    {
        this.name = name;
        this.gdpGrowth = gdpGrowth;
        this.inflation = inflation;
        this.tradeBalance = tradeBalance;
        this.hdiRanking = hdiRanking;
        this.tradePartners = tradePartners;
    }

    public String Name
    {
        set { this.name = value; }
        get { return name; }
    }

    public float GdpGrowth
    {
        set { this.gdpGrowth = value; }
        get { return gdpGrowth; }
    }

    public float Inflation
    {
        set { this.inflation = value; }
        get { return inflation; }
    }

    public float TradeBalance
    {
        set { this.tradeBalance = value; }
        get { return tradeBalance; }
    }

    public float HdiRankings
    {
        set { this.hdiRanking = value; }
        get { return hdiRanking; }
    }

    public LinkedList<String> TradePartners
    {
        set { this.tradePartners = value; }
        get { return tradePartners; }
    }

    public override string ToString()
    {
        return name + ", " + gdpGrowth + ", " + inflation + ", " + tradeBalance + ", " + hdiRanking + ", " + tradePartners;
    }

    public int CompareTo(object other)
    {

           // Country temp = (Country)other;
            //return name.CompareTo(temp.name);
           // throw new StackOverflowException();
        return 1;

    }


}

}

If anyone could help me solve this it would be great, Thanks

Upvotes: 1

Views: 100

Answers (1)

nvoigt
nvoigt

Reputation: 77304

Simply put, your code is not what you compiled:

either this:

public class AVLTree<T>

or this:

public class Country

is not what your compiler compiled. Double check both that they are public, then recompile all.

By the way:

public AVLTree<Country> thing { get { return thing; } set{this.thing = value;}

This is plain wrong and should not compile either. You have build an endless recursion that will result in a StackOverflow at runtime. But your compiler should be smart enough to notice.

Something is off. Your code and your compile errors do not match.

Upvotes: 1

Related Questions