Thread: What does this mean?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    65

    What does this mean?

    Code:
    struct myclass {
      bool operator() (int i,int j) { return (i<j);}
    } myobject;
    I saw this while browsing a C++ reference. I don't understand what myobject is when it's between the } and ;

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It defines an instance of class myclass with the name myobject.
    It's the same as
    Code:
    struct myclass {
      bool operator() (int i,int j) { return (i<j);}
    };
    myclass myobject;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Elysia View Post
    It defines an instance of class myclass with the name myobject.
    rather an instance of struct myclass

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Err, right. My bad >_<
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Code:
    struct {
      bool operator() (int i,int j) { return (i<j);}
    } isSmaller;
    
    int x=10, y=20;
    isSmaller(x, y);
    now it makes more sense!

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    ..rather an instance of struct myclass
    ..which in the context of C++, thus a C++ struct, is the same as a class except that in structs all members default to public.

Popular pages Recent additions subscribe to a feed