overloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mural

    #1

    overloading

    hi everyone....

    im new to this group... cheers to all.
    k then can u suggest me how to overload the 2D subscript operator.
    i get difficulty on passing the second arguement....

  • Victor Bazarov

    #2
    Re: overloading

    mural wrote:
    k then can u suggest me how to overload the 2D subscript operator.
    i get difficulty on passing the second arguement....
    There is no "2D subscript operator". Two major solution strategies exist:
    using a function call operator with two arguments or overloading the normal
    subscript which returns a proxy object which in turn overloads its own
    subscript operator that returns what you need. With both you can basically
    go any number of dimensions. Look up the code in the archives. Use your
    apparent experience on the 'Net to search http://groups.google.com/

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • Phlip

      #3
      Re: overloading

      mural wrote:
      k then can u suggest me how to overload the 2D subscript operator.
      Chat (k, u, etc.) works best in a chat client, because you can immediately
      tell if the reader understands you, and if you need to write more.

      USENET posts must be able to stand alone, to be read offline, and read by
      people with alternative language skills. Always take the time to write
      complete words and sentences here.
      i get difficulty on passing the second arguement....
      This FAQ entry discusses why that's not a good idea:



      As usual with verbiage that warns against doing something, it must hint how
      to do it. "Don't smoke crack. If you do, don't inhale". etc!

      --
      Phlip
      http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


      Comment

      • Jim Langston

        #4
        Re: overloading

        "mural" <murali.cpp@gma il.comwrote in message
        news:1156167364 .492424.310540@ i42g2000cwa.goo glegroups.com.. .
        hi everyone....
        >
        im new to this group... cheers to all.
        k then can u suggest me how to overload the 2D subscript operator.
        i get difficulty on passing the second arguement....
        I asked a similar question before, although I tend to use capitialization
        (I'm) and actually spell out works (Okay, you).

        Basically what I was shown, and have done, was to override the [] operator,
        and it returns a sub object which also has the operator [] overridden.

        My subject was:
        "Can we override [][]?"

        If you google for that and my name you should be able to find the thread
        where this was discussed indepth along with caveats.


        Comment

        • Noah Roberts

          #5
          Re: overloading


          mural wrote:
          hi everyone....
          >
          im new to this group... cheers to all.
          k then can u suggest me how to overload the 2D subscript operator.
          i get difficulty on passing the second arguement....
          This works...

          QUOTE:

          Cute in an "oh god don't ever do that" sort of way:

          struct MagicInt {
          // operator overloads, constructors, etc, to make this class behave
          // as an integer.

          };

          std::pair<Magic Int, MagicIntoperato r , (const MagicInt &a, const
          MagicInt& b) { return std::make_pair( a, b); }

          class Array2d {
          public:
          value& operator[](const std::pair<Magic Int, MagicInt&a) {
          // use a.first and a.second to find the value...
          }

          };

          int main() {
          Array2d M(X, Y);

          for (MagicInt a = 0; a < X; ++a)
          for (MagicInt b = 0; b < Y; ++b)
          M[a, b] = i + j;

          }

          So, 'M[a, b]' is *implementable* , even if so brittlely that you'd never
          want to use it. (For instance, you cannot say 'M[1, 2]'.)

          Jack Saalweachter

          Comment

          • mural

            #6
            Re: overloading

            yeah..!
            thank u...
            and i am new to groups...
            hereafter i will try to eliminate that kind of posts...

            Phlip wrote:
            mural wrote:
            >
            k then can u suggest me how to overload the 2D subscript operator.
            >
            Chat (k, u, etc.) works best in a chat client, because you can immediately
            tell if the reader understands you, and if you need to write more.
            >
            USENET posts must be able to stand alone, to be read offline, and read by
            people with alternative language skills. Always take the time to write
            complete words and sentences here.
            >
            i get difficulty on passing the second arguement....
            >
            This FAQ entry discusses why that's not a good idea:
            >

            >
            As usual with verbiage that warns against doing something, it must hint how
            to do it. "Don't smoke crack. If you do, don't inhale". etc!
            >
            --
            Phlip
            http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

            Comment

            • mural

              #7
              Re: overloading

              and my question is
              " how can i overload a subscript operator with more than one dimension
              like [][][].."

              with regards
              murali
              Phlip wrote:
              mural wrote:
              >
              k then can u suggest me how to overload the 2D subscript operator.
              >
              Chat (k, u, etc.) works best in a chat client, because you can immediately
              tell if the reader understands you, and if you need to write more.
              >
              USENET posts must be able to stand alone, to be read offline, and read by
              people with alternative language skills. Always take the time to write
              complete words and sentences here.
              >
              i get difficulty on passing the second arguement....
              >
              This FAQ entry discusses why that's not a good idea:
              >

              >
              As usual with verbiage that warns against doing something, it must hint how
              to do it. "Don't smoke crack. If you do, don't inhale". etc!
              >
              --
              Phlip
              http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

              Comment

              • Thomas J. Gritzan

                #8
                Re: overloading

                mural schrieb:
                and my question is
                " how can i overload a subscript operator with more than one dimension
                like [][][].."
                Both Victor Bazarov and Jim Langston provided an answer. Just read.

                And please don't top-post.

                --
                Thomas

                Comment

                • Default User

                  #9
                  Re: overloading

                  mural wrote:
                  yeah..!
                  thank u...
                  and i am new to groups...
                  hereafter i will try to eliminate that kind of posts...
                  Please don't top-post. Your replies belong following or interspersed
                  with properly trimmed quotes. See the majority of other posts in the
                  newsgroup, or the group FAQ list:
                  <http://www.parashift.c om/c++-faq-lite/how-to-post.html>



                  Brian

                  Comment

                  Working...