Thread: passing pointers to a class function

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    16

    passing pointers to a class function

    ok so i have this

    Code:
    class Poly{
    private:
    struct node {						int exponent;			
    	double coefficient;			
    	struct node *next;
    };
    typedef struct node ListNode;
    
    ListNode *first;
    
    public:
              Poly(){ first = NULL;}
              
               etc....
    };
    
    Poly* Poly::addPoly(Poly *p2)
    {
    if(product!=NULL && temp!=NULL)
    stuff
    }
    
    Poly* Poly::multiplyPoly(Poly *p2)
    {
    Poly *temp = new Poly();
    Poly *product = new Poly();
    
    product->addPoly(temp);  (assuming product and temp have values
                                               but when i pass it, it sets product->first=NULL
                                               which in the function addPoly, it ignores the if loop 
                                               which i need it to go through. is there a way to make
                                               product->first!=NULL the two 
                                               objects are passed?)
    error C2262: 'I' : cannot be destroyed

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I don't think you're showing entirely real code. product can't be referenced from Poly::addPoly() unless I'm missing something.

    Please try to show a real but small and yet complete demonstration of what the issue is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. passing counters between function
    By BungleSpice in forum C Programming
    Replies: 18
    Last Post: 02-21-2004, 06:16 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM