Click to See Complete Forum and Search --> : non-static member of outer type


vivendi
October 8th, 2009, 02:56 AM
Hey, i get the following error when i try to compile my project:

Cannot access a non-static member of outer type 'Project.Shader' via nested type 'Project.Shader.RenderSurfaceSet'.

What i'm doing is the following.
I have a class called worldView.cs, in that class i create the Shader class like so:

[Inside worldView.cs]

Shader shader = new Shader(this);


As you can see a pass an instance of the worldView class to the shader class. The shader class uses some variabled declared in the worldView class without a problem.
But here comes the issue:

In the Shader.cs class i also have a struct defined inside the class, like so:


public class Shader
{
public View.WorldView world;

RenderSurfaceSet[] downscaledSets;

public Shader(View.WorldView world)
{
this.world = world;
Initialize();
}

//some functions inside the class

//the struct
struct RenderSurfaceSet
{
//some variables here

public RenderSurfaceSet(int downscalingFactor, int sourceTexture)
{
//code in constrcutor
}
//and some other functions inside this struct
}
}


Now what i'm trying to do is also use the worldView instance inside this struct. The worldView object seems to be accessible from within that struct, but when i try to compile it it generates that error.

Anyone any idea how to solve that??

vcdebugger
October 8th, 2009, 04:17 AM
can you point out the line in the code inside the structure where this error is pointing?
Is it inside the function with the structure or in assigment or just reading the value inside the structure?

BigEd781
October 8th, 2009, 11:41 AM
Well, you have omitted the code which is actually causing the error, but your struct will not be able to access non-static data defined in your Shader class. This would be true for any class or struct, regardless of where/how it was defined. You are probably trying to access instance variables with no instance of "Shader" to refer to.

vcdebugger
October 8th, 2009, 11:46 PM
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct ParserFunctionInfoTry
{

public class Parameters
{
#region Parent Class
public CTElement parentClass = null;
#endregion

#region Name
private String _name;
[Browsable(true)]
[Category("Data")]
public String Name
{
get { return _name; }

set { _name = value; }
}
}

Parameters _param;
public List<Parameters> _paramLst;
[Browsable(true)]
[Category("Data")]
public List<Parameters> parameterLst
{

get
{
return _paramLst;
}

set { _paramLst = value; }
}
}



here I have a case where a class is defined inside a structure and accessible with in that structure....