CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Location
    Montreal
    Posts
    58

    Overloading the [] operator

    I am working with a mix of C# and Managed C++ in my project.

    I need to know what the syntax is to overload the [] operator.

    My class derrives from System::ArrayList. The documents say that the Item property is an overload to the index subscript [].

    What is the syntax in C++ to define this in my derrived class? I can't find anything on this and I can not see any op_... to use for this.

    Anyone know how to do it?

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Overloading the [] operator

    See how operator[] is implemented in ArrayList class:

    Code:
    C#
    public virtual object this[int index] 
    {get; set;}
    
    C++
    public: __property virtual Object* get_Item(
       int index
    );
    public: __property virtual void set_Item(
       int index,
       Object*
    );
    Use the same C++ prototype.

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