CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 6 of 6

Thread: Issues overloading [] operator

Threaded View

  1. #1
    Join Date
    Jan 2009

    Issues overloading [] operator

    Hey guys,

    I can't seem to get the declaration for overloading the [] operator correctly.

    friend const int& operator[] (unsigned int argInt);
    const int& operator[] (unsigned int argInt){
            if (getDegree() > argInt){
    		return 0;
    		for (int i = 0; i < nCoeff; ++i){
    			if (degrees[i] == argInt){
    				return coeff[i];
    [edit] I also tried const int& Polynomial:perator[] but it gave me an error saying 'binary '[' : 'Polynomial' does not define this operator or a conversion to a type acceptable to the predefined operator'

    First off my syntax for overloading this operator is incorrect but I do not know where.

    Also it can't find getDegree() nCoeff, degrees and coeff - these are variables (and one function) that are available in the class but because I have no reference to the object - I don't know how to access the object.

    When overloading other operators ++ I have access to the object - is there a way I can access the object in the [] operator?

    Thanks in advance,
    Last edited by Lang; February 28th, 2009 at 04:32 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)