I write a small program to encounter the next day by giving day.
I write a program in day_enum.cpp file:-
#include <ostream>
#include "AllHeader.h"
using namespace std;
inline days operator++(days d)
{
return static_cast<days>((static_cast<int>(d) + 1) % 7);
}
ostream& operator<< (ostream& out,const days& d)
{
switch (d)
{
case SUN: out <<"SUN";
break;
case MON: out <<"MON";
break;
case TUE: out<<"TUES";
break;
case WED: out <<"WED";
break;
case THUS: out <<"THUS";
break;
case FRI: out <<"FRI";
break;
case SAT: out << "SAT";
break;
default:
break;
return out;
}
}
Now allheader.h file look like this:-
#pragma once
#ifndef AllHeader
#define AllHeader
typedef enum days { SUN, MON, TUE, WED, THUS, FRI, SAT } days;
inline days operator++(days d);
ostream& operator<< (ostream& out, const days& d) ;
#endif
In main function:-
days d = MON, e;
e = ++d;
cout << d << '\t' << e << endl;
I am getting error :- LNK2019 unresolved external symbol "enum days __cdecl operator++(enum days)" (??E@YA?AW4days@@W40@@Z) referenced in function main.
As per my understanding I already declare it in allheader.h file.
According to the C++ Standard
An inline function or variable shall be defined in every translation unit in which it is odr-used outside of a discarded statement.
It seems in the translation unit with main
there is no definition of your inline function (operator).
Place the definition of the function in the header.