View Full Version : Visual C# accessability error
Al6200
January 29th, 2007, 07:40 AM
So, I was designing this little program that simulates units which implement behaviorist logic.
And I get this error. One might call it "stupid", as it is wholly frivolous.
Error 1 Inconsistent accessibility: field type 'neuronNameSpace.neuron[]' is less accessible than field 'neuronHandleNameSpace.neuronHandle.NeuronArray'
Anywho, I have a class called neuron and a class called neuronHandle.. In the constructor of neuronHandle I have a static public definition of an array of neurons.
So what is the problem??? Why can't I create an array in another class of another object type.
Al6200
January 29th, 2007, 08:43 PM
WHY?!?!?!?!?!?!?
HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
:stare::stare::stare::stare::stare::stare::stare:: stare::stare::stare::stare::stare::stare::stare::s tare::stare::stare::stare::stare::stare::stare::st are::stare::stare::stare::stare::stare::stare::sta re::stare::stare::stare::stare::stare::stare::star e::stare::stare::stare::stare::stare::stare::stare ::stare::stare::stare::stare::stare::stare::stare: :stare::stare::stare::stare::stare::stare::stare:: stare::stare::stare:
Now you see why I need to write a code that creates intelligent life!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
kirupa
January 29th, 2007, 09:01 PM
What is the access modifier for your neoron[] and NeuronArray[] fields? Are they both public, for example?
Al6200
January 29th, 2007, 10:22 PM
Neuron is a class, and its public. NeuronArray is public static, it is in its own class, seperate from neuron class. It must be public so it can be accessed by the neuron class.
kirupa
January 30th, 2007, 12:02 AM
Can you zip up the source and post it here? Inheritance can be tricky, so I'd prefer being able to see the code :)
Al6200
January 30th, 2007, 06:56 AM
Okay, uploaded. I can't really see why the Visual Studio compiler feels compelled to call something that feels like an organizational issue a fatal error. Its really weird for someone used to the Flash compiler, which allows all sorts of mischief before an error occurs.
kopo.fett
January 30th, 2007, 09:04 PM
I'm not at home so I'm unable to view your source, but I'm pretty sure its the fact that NeuronArray is static.
Static types can only be accessed via the class its declared in.
string s = NeuronHandle.NeuronArray[];
But if you were to create a new instance of the class that contains the static type you wouldn't see it only the public methods and so on.
NeuronHandle newNeuron = new NeuronHandle();
newNeuron.WhatEverPublicMethods();
Mmmm, i'm still learning c# so I could be wrong and completely off track :thumb: lol.
Al6200
January 30th, 2007, 09:27 PM
You could very well be right. But what's the point of a static method if it can't be public?
kopo.fett
January 31st, 2007, 08:24 PM
Static methods can be public and still be accessed outside the class so long as the class accessor is public.
Have you got a brief or can you describe what you wanted to achieve with the code. I viewed it and without comments wasn't able to see what you wanted to get out of it. I also saw some possible errors that could be fixed.
ie:
public class neuronHandle
{
public static int numNeurons;
public neuron[] NeuronArray;
public neuronHandle(int numNeuronsIn)
{
numNeurons = numNeuronsIn;
NeuronArray = new neuron[numNeurons];
}
}
should look something like this:
public class NeuronHandle
{
// Declare an int type to specify the array length
private int numNeurons;
// Declare the neuron array
int[] neuronArray;
// NeuronHandle initialiser
public neuronHandle(int numNeuronsIn)
{
numNeurons = numNeuronsIn;
// Initialise the neuronArray with a length
neuronArray = new int[numNeurons];
}
} So basically when you want to create your object. You'll type:
NeuronHandle neuronArrayOne = new NeuronHandle(x)
Where x is the input from the user or where ever you wanted to get the input value from. Also you dont really need the numNeurons int declared in the class scope, unless you have another use for it later on. This is only if that was what you wanted to achieve. But let me know where you wanted to go with the code and I'll see where I can help.
Al6200
January 31st, 2007, 09:26 PM
But neuronhandle isn't an array of int, its an array of neurons. I guess I could try not making it static though, and make it so it requires an instance. But I don't really see why static vars exist if they aren't public. Since they by nature affect the class, not a specific instance.
kopo.fett
February 2nd, 2007, 01:44 AM
Oh now I understand the neuron[]. So what then is the purpose of the neuronHandle class? To create an array of neurons/neuron classes? But static types/variables are allowed to be public. But can only be used/manipulated by static methods which means the class must be static too.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.