Question

I'm trying to run this c++ program I wrote. I'm getting the following errors in Visual C++:

1>c:\users\server\desktop\problem7\problem7\main.cpp(26) : error C3867: 'Payment::getamount': function call missing argument list; use '&Payment::getamount' to create a pointer to member

1>c:\users\server\desktop\problem7\problem7\main.cpp(74) : error C3867: 'cashPayment::paymentDetails': function call missing argument list; use '&cashPayment::paymentDetails' to create a pointer to member

1>c:\users\server\desktop\problem7\problem7\main.cpp(75) : error C3867: 'CreditCardPayment::paymentDetails': function call missing argument list; use '&CreditCardPayment::paymentDetails' to create a pointer to member

the code is:

#include <iostream>
#include <cstring>
using namespace std;

class Payment
{
private: float amount;

public: Payment(float=0.0);
        void paymentDetails();
        float getamount();
        void setamount(float);
};


Payment::Payment(float a)
{
    setamount(a);
}

void Payment::setamount(float a){amount=a;}
float Payment::getamount(){return amount;}

void Payment::paymentDetails()
{
    cout<<"The amount of payment is : "<<getamount<<"$"<<endl;
}

class cashPayment: public Payment
{
public: cashPayment(float=0.0);
        void paymentDetails();
};
cashPayment::cashPayment(float a):Payment(a){};
void cashPayment::paymentDetails()
{
    cout<<"The payment in cash is : "<<getamount()<<"$"<<endl;
}

class CreditCardPayment: public Payment
{
private: char* name;
         int creditnumber;
         int day,month,year;

public: CreditCardPayment(char[]=" ",int=0, int=0, int=0, int=0 ,float=0.0);
        void paymentDetails();
};

CreditCardPayment::CreditCardPayment(char* n, int cn, int d, int m, int y, float a):Payment(a)
{
    int l=strlen(n);
    name = new char[l+1];
    strncpy(name,n,l);
    name[l]='\0';
    creditnumber=cn;
    day=d;
    month=m;
    year=y;
}
void CreditCardPayment::paymentDetails()
{
    cout<<"Credit Card Holder Information & Payment: "<<endl;
    cout<<"Name is "<<name<<endl;
    cout<<"Credit Number is "<<creditnumber<<endl;
    cout<<"Expiration Date (Day / Month / Year) is "<<day<<"/"<<month<<"/"<<year<<endl;
    //cout<<"Payment is "<<Payment::getamount()<<"$"<<endl;
}

int main()
{
    CreditCardPayment cc1("Mohammad",936623,21,9,2011,3000);
    cashPayment cp1(4500);
    cp1.paymentDetails;
    cc1.paymentDetails;

    system("pause");
    return 0;
}
Was it helpful?

Solution

In here:

void Payment::paymentDetails()
{
    cout<<"The amount of payment is : "<<getamount<<"$"<<endl;
}

the compiler is telling you that you might have meant getamount() instead of getamount.

Similarly here:

cp1.paymentDetails;
cc1.paymentDetails;

you probably meant:

cp1.paymentDetails();
cc1.paymentDetails();

Unlike some other languages, in C++ when you call a function that takes no arguments you must still provide an empty argument list in parentheses.

OTHER TIPS

cp1.paymentDetails;
cc1.paymentDetails;

The error states "function call missing argument list." Your function calls are indeed missing the argument lists. You need to use () to call the functions:

cp1.paymentDetails();
cc1.paymentDetails();

The second half of the error, which reads "'&Payment::getamount' to create a pointer to member" is a "helpful" hint that if you meant to take the address of the function, you need to use the unary & (address-of) operator.

This hint is there because the operator is not required for computing the address of a non-member function (for compatibility with C and for legacy code), but it is required for computing the address of a nonstatic member function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top