CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    102

    non-static member of outer type

    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]
    Code:
    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:

    Code:
        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??
    Last edited by vivendi; October 8th, 2009 at 03:10 AM.

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: non-static member of outer type

    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?

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: non-static member of outer type

    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.
    Last edited by BigEd781; October 9th, 2009 at 01:16 AM.

  4. #4
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: non-static member of outer type

    Code:
     [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....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured