Thread: calling the class within the public...help!

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    calling the class within the public...help!

    I think this is a pretty simple problem, but I just can't get it, I have the following class:

    Code:
    class Polynomial
      {
      private:
       int coeff[LEN];
    
      public:
       Polynomial ();
       Polynomial Add (const Polynomial& P2) const;
       Polynomial Subtract (const Polynomial& P2) const;
       void Print (unsigned wid=0) const;
       unsigned width () const;
       void setCoeff (unsigned index, int newCoeff);
      };
    
    Polynomial::Polynomial()
      {
      for (unsigned i=0; i<LEN; i++)
        {
        coeff[i]=0;
        }
      }
    I'm trying to implement the Add member but I can't figure out how to access what's in P2

    I've tried

    Code:
    Polynomial Polynomial::Add (const Polynomial& P2) const
      {
      Polynomial Ptemp;
      for (unsigned i=0; i<LEN; i++)
        {
        Ptemp = coeff[i] + P2[i];
        }
      return Ptemp;
      }
    and then it gives me complier error "no match for `Polynomial &[unsigned int &]'"

    So I don't know really what to do, any help would be nice

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    EDIT: I read the question too fast. See the post below this one for some insight
    Last edited by bithub; 03-24-2006 at 04:24 PM.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
     Ptemp = coeff[i] + P2.coeff[i];
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Thanks for the quick response guys... I feel kinda stupid for not realizing what I needed to do :\

    But i'm still getting the error

    **no match for `Polynomial &[unsigned int &]'**

    for this line:
    Code:
    Ptemp[i] = coeff[i] + P2.coeff[i];
    any ideas?


    *edit*
    actually i think i figured it out - just had to change it to
    Code:
    Ptemp.coeff[i] = coeff[i] + P2.coeff[i];
    Last edited by PPhilly; 03-24-2006 at 04:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 06-18-2009, 04:58 AM
  2. Reading Process Memory
    By polydegmon in forum C# Programming
    Replies: 0
    Last Post: 05-26-2009, 07:18 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  5. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM