dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Static member cannot be accessed Error

  1. #1
    Join Date
    Apr 2007
    Posts
    42

    Static member cannot be accessed Error

    I'm trying to call a public static void method (setFiles(variable)) in another class. I create a new class object (ht) and attach the method (.setFiles()) with the variable it needs (sw) but i get a "Static member cannot be accessed with an instance reference; qualify it with a type name instead" error.

    this is how i call the method which is getting the error:

    ht.setFile(sw);

    what is the problem? i have no idea

  2. #2
    Join Date
    Jul 2006
    Posts
    59

    Re: Static member cannot be accessed Error

    A static member function does not belong to a specific instance of a class but rather to the class type itself. As a result, when you are attempting to access it for a specific instance, the compiler is not allowing this.

    To call the function correctly, you would have to write

    classname.setFiles(sw)

    rather than

    ht.setFile(sw)

    or remove the static modified.
    If my posts have helped you, please rate them. Ratings give me that warm, fuzzy feeling of having helped someone out

  3. #3
    Join Date
    Apr 2007
    Posts
    42

    Re: Static member cannot be accessed Error

    oh i get it now, i've been searching around the web and your explanation was actually the best i've found, thanks

  4. #4
    Join Date
    Jul 2006
    Posts
    59

    Re: Static member cannot be accessed Error

    Glad I could help
    If my posts have helped you, please rate them. Ratings give me that warm, fuzzy feeling of having helped someone out

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)