Override specifier

Hi can you help me to fix the error in Invoice class .h - " dt Unknown override specifier"

I think its something in Invoice.h file when i declarate "Date dt", but i dont know how to fix it

Thanks in advance

Date .h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include "Stock.h"
#include "Invoice.h"
#include <ostream>
#include <iostream>

class Date {

    int month, day, year;

public:

    Date();

    Date(int _month, int _day, int _year);


    Date& setMonth(int _month);
    Date& setDay(int _day);
    Date& setYear(int _year);

    int getMonth() const;
    int getDay() const;
    int getYear() const;

    void showDate();

    friend std::ostream& operator<<(std::ostream& ou, const Date& d);
};


Date cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Date.h"
#include <iostream>


Date::Date() {

    month = 0;
    day = 0;
    year = 0;
}

Date::Date(int _month, int _day, int _year) {

    month = _month;
    day = _day;
    year = _year;
}


Date& Date::setMonth(int _month)
{
    month = _month;
    return *this;
}

Date& Date::setDay(int _day)
{

    day = _day;
    return *this;
}

Date& Date::setYear(int _year)
{
    year = _year;
        return *this;
}

//getters

int Date::getMonth() const
{
    return month;
}

int Date::getDay() const
{
    return day;
}

int Date::getYear() const
{
    return year;
}

void Date::showDate()
{
    std::cout <<"Month " << month << " / " <<"Day "<< day << " / " << "Year "<<year << std::endl;
}

std::ostream& operator << (std::ostream& ou, const Date& d)
{
    ou << "\nMonth : " << d.getMonth();
    ou << "\nDay : " << d.getDay();
    ou << "\nYear : " << d.getYear();
        return ou;
}


Invoice h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include"Stock.h"
#include "Date.h"
#include <string>
#include<map>
#include <iomanip>
#include <sstream>
#include<iostream>
#include <algorithm>

class Invoice 
{
    int numberInvoice;
    Date dt; 
    std::map<Stock, double> goods;
public:
    Invoice() ;
    Invoice(int _numberInvoice, Date _dt, std::map<Stock, double> _goods);
    int getNumberInvoice() const;
    Date getDate()const;

    std::map<Stock, double> getGoods() const;

    void setNumberInvoice(int _numbInvoice);

    Invoice& setDate(Date _date);

    void setGoods(std::map<Stock, double> _goods);

    void addGood(Stock s);
    void display()const;
    void showByCode(int code);
    void calcGoods();
};


Invoice cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Invoice.h"
#include "Date.h"
Invoice::Invoice()
{
}

Invoice::Invoice(int _numberInvoice, Date _dt, std::map<Stock, double> _goods)
{
    numberInvoice = _numberInvoice;
    dt = _dt;
    goods = _goods;
}

int Invoice::getNumberInvoice() const
{
    return numberInvoice;
}


Date Invoice::getDate() const
{
    return dt;
}

std::map<Stock, double> Invoice::getGoods() const
{
    return goods;
}

void Invoice::setNumberInvoice(int _numbInvoice)
{
    numberInvoice = _numbInvoice;
}


Invoice& Invoice::setDate(Date _dt) {
    dt = _dt;
    return *this;
}

void Invoice::setGoods(std::map<Stock, double> _goods)
{
     goods = _goods;
}


void Invoice::addGood(Stock s)
{

}

void Invoice::display() const
{
    std::cout << "\nInvoice " << numberInvoice << '\n';
    std::cout << "Date of issue " << dt << '\n';
    std::cout << "Goods:\n";

        for (const auto& kv : goods) {
            std::cout << kv.first <<"Has value: "<< kv.second<< std::endl;
        }
}
Last edited on
One thing I see is that your Invoice.h #includes Date.h, but your Date.h #includes Invoice.h. Your Date.h does not appear to depend on Invoice.h, so it does not need to include it.

You should also put proper include guards in your headers.
https://en.wikipedia.org/wiki/Include_guard#Use_of_#include_guards
Last edited on
Topic archived. No new replies allowed.