我正在使用C ++开展学校作业,并且我已经使用构造函数实现了一个头文件:
#include <iostream>
#include <stdlib.h>
using namespace std;
class Shopper
{
public:
Shopper::Shopper(int yrs_a_mbr, double av_mnth_prchs, char* sh_nm);
int years_a_member;
double avg_month_purchases;
double membership_cost;
double nominal_membership_cost;
private:
};
每当我编译时,编译器都会给我一个错误,说明&#34;额外的资格错误&#34;在线
Shopper::Shopper(int yrs_a_mbr, double av_mnth_prchs, char* sh_nm);
我看过各种各样的例子,但仍然无法看清我做错了什么。
答案 0 :(得分:1)
@ Jan.Jedrasik其他消息是链接器错误。请参阅What is an undefined reference/unresolved external symbol error and how do I fix it?(或者您可能需要定义
main
)
<强> Live On Coliru 强>
#include <iostream>
using namespace std;
class Shopper {
public:
Shopper(int yrs_a_mbr, double av_mnth_prchs, char const*sh_nm) : years_a_member(yrs_a_mbr),
avg_month_purchases(av_mnth_prchs),
membership_cost(0), nominal_membership_cost(0)
{}
int years_a_member;
double avg_month_purchases;
double membership_cost;
double nominal_membership_cost;
private:
};
int main() {
Shopper big(1, 17, "John Doe");
}
提示:
std::string