Help with error: invalid use of member (did you forget the '&' ?)

This is a discussion on Help with error: invalid use of member (did you forget the '&' ?) within the C++ Programming forums, part of the General Programming Boards category; HI. I'm new to programming. can someon help me explain this error? insert Code: //Jeff Chhouk //Package Shipping Project #include ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    2

    Help with error: invalid use of member (did you forget the '&' ?)

    HI. I'm new to programming. can someon help me explain this error?

    insert
    Code:
    //Jeff Chhouk
    //Package Shipping Project
    #include <iostream>
    using namespace std;
    
    class Package// declare base class
    
    
    {
    private:
    public:
       Package(char *, char *);  //constructor
      ~Package(); //destructor
       virtual float calcShipcost()=0;  //zero to make abstract
       virtual void print()=0;
    protected:   
    
    char *first, *last;  //for first and last name
    
       int Numofitems;
       int overnightd();
       int insurance();
       
    };
    
    
    Package :: Package(char *f, char *l)
    {
    first=new char[strlen(f)+1];
    strcpy(first, f);
    last= new char [strlen(l)+1];
    strcpy(last, l);
    }
    
    Package::~Package() // using destructor
    {
      delete[] first;
      delete[] last;
    }
    
    void Package:: print()
    { 
       cout<< first<< "  " << last;
    }
    
    
    
    
    
    class Tshirts : public Package // declaring derived class of tshirts with base class of Package
    
    {
    
    
    
    
    public:
       Tshirts();// constructor
      ~Tshirts(); //destructor
      virtual float calcShipcost();
    };
    
    float Tshirts:: calcShipcost()
    {
    
      if(overnightd==1 && insurance==1 )//zero no and one is yes
     return (Numofitems*2.75)+10+(.02*(Numofitems*2.75));//for yes on insuranances and yes delivery
       
    else  if      (overnightd==1 && insurance==0)
       return (Numofitems*2.75)+10;
     else  if    (overnightd==0  && insurance==1)
         return(Numofitems*2.75)+(.02*(Numofitems*2.75)) ;
    else   
        (overnightd==0 && insurance==0)
         return(Numofitems*2.75) ;
          
    }
    
    Void Tshirts:: print()
    ]{
    cout<<"T shirts cost is:";
    Package::print();
    }
    
    
    
    int main
    {
    
    Tshirt tees("Joe", "Smith" 2,1,0);
    tees.print();//T shirts cost is:$15.50
    cout<<"$"<<tees.calc Shipcost()<<endl;
    
    
    system("PAUSE");// must be before return 0
    return o;
    }
    Output:
    t.cpp: In member function 'virtual float Tshirts::calcShipcost()':
    Line 66: error: invalid use of member (did you forget the '&' ?)
    compilation terminated due to -Wfatal-errors.


    I bold the error line.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You defined overnight as a function pointer. If you intended to call the function, then you should use the function call notation (that is, a set of parentheses afterward). Same for insurance.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    2
    Thank you! I took the parentheses out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid subscript error
    By MrDanny in forum C++ Programming
    Replies: 9
    Last Post: 05-02-2011, 01:59 PM
  2. error: invalid conversion from 'int' to 'int*'
    By csharp100 in forum C++ Programming
    Replies: 4
    Last Post: 02-22-2011, 07:56 AM
  3. Error: invalid use of member (did you forget the ‘&’ ?)
    By blacknail in forum C++ Programming
    Replies: 6
    Last Post: 11-06-2008, 12:01 PM
  4. 'Invalid Use of Member'
    By stu673 in forum C++ Programming
    Replies: 5
    Last Post: 02-10-2005, 11:42 AM

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