-1

I'm working on a school assignment in C++, and I've implemented a header file with a constructor:

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

Whenever I compile, the compiler gives me an error saying "extra qualification error" on the line

Shopper::Shopper(int yrs_a_mbr, double av_mnth_prchs, char* sh_nm);

I've looked at various examples and I still can't see what I'm doing wrong.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Jan .Jedrasik
  • 63
  • 1
  • 5
  • 4
    Omit the `Shopper::`, you don't specify the class until you provide the implementation. – Ryan J Nov 27 '15 at 23:52
  • I've already tried this unfortunetely, it gives me a plethora of errors regarding something something relocation has invalid index.. – Jan .Jedrasik Nov 27 '15 at 23:53
  • Show your associated source code... – Ryan J Nov 27 '15 at 23:55
  • @Jan.Jedrasik that other message is a linker error. See https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix (or maybe you need to define `main`) – sehe Nov 27 '15 at 23:55
  • Please show is the file which you compile, that includes this header. – Jens Nov 27 '15 at 23:55
  • "Relocation has invalid index" is a linker error most commonly seen when you don't define a `main()` function... – Ryan J Nov 27 '15 at 23:57
  • 1
    Omitting `Shopper::` is the correct answer to the question you have posted. If you get other errors then they are a different issue; you should accept the answer posted by sehe here and ask a new question about the other errors. (if you can't solve them first of course..) – M.M Nov 28 '15 at 00:24

1 Answers1

1

@Jan.Jedrasik that other message is a linker error. See What is an undefined reference/unresolved external symbol error and how do I fix it? (or maybe you need to define 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");
}

Hints:

  1. use std::string
  2. don't store values that are derivatives
  3. perhaps store the tariff information outside the Shopper (unless you're sure that shopper have their own individual (nominal) fees?)
sehe
  • 374,641
  • 47
  • 450
  • 633