gpt4 book ai didi

c++ - 我正在尝试调用一个函数。这些愚蠢的编译错误的原因是什么?

转载 作者:行者123 更新时间:2023-11-28 03:42:04 25 4
gpt4 key购买 nike

我正在尝试运行我编写的这个 C++ 程序。我在 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

代码是:

#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;
}

最佳答案

在这里:

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

编译器告诉您,您的意思可能是 getamount() 而不是 getamount

同样在这里:

cp1.paymentDetails;
cc1.paymentDetails;

你的意思可能是:

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

与某些其他语言不同,在 C++ 中,当您调用不带参数的函数时,您仍然必须在括号中提供一个空参数列表。

关于c++ - 我正在尝试调用一个函数。这些愚蠢的编译错误的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8857775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com