[英]Unresolved external symbol "enum days __cdecl operator++(enum days)" (??E@YA?AW4days@@W40@@Z) referenced in function main
I write a small program to encounter the next day by giving day.我写了一个小程序,通过给日遇到第二天。
I write a program in day_enum.cpp file:-我在 day_enum.cpp 文件中编写了一个程序:-
#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:-现在 allheader.h 文件如下所示:-
#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:-在主要 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.我收到错误:- function main 中引用的 LNK2019 未解析的外部符号“枚举天数 __cdecl 运算符++(枚举天数)”(??E@YA?AW4days@@W40@@Z)。
As per my understanding I already declare it in allheader.h file.据我了解,我已经在 allheader.h 文件中声明了它。
According to the C++ Standard根据C++标准
An inline function or variable shall be defined in every translation unit in which it is odr-used outside of a discarded statement.
内联 function 或变量应在每个翻译单元中定义,在该翻译单元中,在废弃语句之外使用它。
It seems in the translation unit with main
there is no definition of your inline function (operator).似乎在带有
main
的翻译单元中没有定义您的内联 function (运算符)。
Place the definition of the function in the header.将 function 的定义放在 header 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.