class design

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashokd008
    New Member
    • Aug 2008
    • 4

    class design

    How do i write a class 'foo' so that the following code works:
    foo f;
    f()()();


    Can anyone tell me what this f()()() mean?
    Thanks in advance.
    -Ashok
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    i dont think f()()() is a valid declaration in C++.
    From where did u get this code?

    raghu

    Comment

    • ashokd008
      New Member
      • Aug 2008
      • 4

      #3
      Originally posted by gpraghuram
      i dont think f()()() is a valid declaration in C++.
      From where did u get this code?

      raghu

      It think it is a valid one. I am really searching for it.

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        It's pointer to function returning pointer to function returning... 3 times such.
        Code:
        typedef int (*fp)();
        typedef fp (*fp1)();
        typedef fp1 (*foo)();
        Don't ask me though how to write it in one declaration without three typedefs.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Make class foo overload the function operator () and make that operator return
          a reference to 'this'. That way you can even do f()()()()()()() ... ()()() as many
          times as your want.

          kind regards,

          Jos

          Comment

          • gpraghuram
            Recognized Expert Top Contributor
            • Mar 2007
            • 1275

            #6
            Originally posted by JosAH
            Make class foo overload the function operator () and make that operator return
            a reference to 'this'. That way you can even do f()()()()()()() ... ()()() as many
            times as your want.

            kind regards,

            Jos

            This is a very good learning for me....
            Thanks lot Jos.

            Comment

            • vinothg
              New Member
              • Oct 2006
              • 21

              #7
              Nice one !!!

              #include <iostream>

              using namespace std;

              class foo{
              public:
              foo& operator () (){
              return *this;
              }
              };

              int main(){
              foo()()()()()() ()()();
              getchar();
              }

              Comment

              • ashokd008
                New Member
                • Aug 2008
                • 4

                #8
                Thanks a lot.. great ....

                Comment

                Working...