calling the class within the public...help!

This is a discussion on calling the class within the public...help! within the C++ Programming forums, part of the General Programming Boards category; I think this is a pretty simple problem, but I just can't get it, I have the following class: Code: ...

  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,264
    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, 05:58 AM
  2. Reading Process Memory
    By polydegmon in forum C# Programming
    Replies: 0
    Last Post: 05-26-2009, 08:18 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 09:38 PM
  5. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21