What does this mean?

This is a discussion on What does this mean? within the C++ Programming forums, part of the General Programming Boards category; Code: struct myclass { bool operator() (int i,int j) { return (i<j);} } myobject; I saw this while browsing a ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    ..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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21