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

Thread: Need help

  1. #1
    Join Date
    Jul 2015
    Posts
    2

    Need help

    I made a class then I recall it but the codes doesn't display

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need help

    Your code is broken.

  3. #3
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Need help

    Quote Originally Posted by Arjay View Post
    Your code is broken.


    RezaBagherian2, you clearly need to provide more information, how about showing the code with which you have an issue?

  4. #4
    Join Date
    Jul 2015
    Posts
    2

    Re: Need help

    the class in the program
    public static class message
    {
    public message()
    {
    MessageBox.show("welcome to the world of programming");
    }
    }
    and how recalled the class
    var c1 = new message
    c1.message();
    every thing is OK the visual studio 2010 didn't show any kind of errors but when i run the program the message didn't show up

  5. #5
    Join Date
    Jul 2015
    Posts
    12

    Re: Need help

    Make your message() static as well. You can't access a non-static method in a static class, even when instantiating it.
    Last edited by DaddyWritesCode; July 23rd, 2015 at 02:14 PM.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need help

    Quote Originally Posted by RezaBagherian2 View Post
    the class in the program
    public static class message
    {
    public message()
    {
    MessageBox.show("welcome to the world of programming");
    }
    }
    and how recalled the class
    var c1 = new message
    c1.message();
    every thing is OK the visual studio 2010 didn't show any kind of errors but when i run the program the message didn't show up
    The code you posted doesn't compile. You need to get the code to compile before it will run.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need help

    Quote Originally Posted by DaddyWritesCode View Post
    Make your message() static as well. You can't access a non-static method in a static class, even when instantiating it.
    Unfortunately that isn't a method (as methods need to return either void or a value). It's more like a constructor, but you can't have a non static constructor inside a static class.

Tags for this Thread

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