简体   繁体   English

function main 中引用的未解析外部符号“enum days __cdecl operator++(enum days)”(??E@YA?AW4days@@W40@@Z)

[英]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.

相关问题 错误 LNK2019 未解析的外部符号 _main 在 function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中引用 - Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 使用 Enum 表示天数 - Using Enum to represent days 枚举类型星期几 - Enum type Days of the week 函数_main中引用的未解析的外部符号“” - unresolved external symbol “” referenced in function _main 函数_main中引用的未解析的外部符号“ *” - Unresolved external symbol “*” referenced in function _main 函数___tmainCRTStartup中引用的未解析的外部符号_main - unresolved external symbol _main referenced in function ___tmainCRTStartup 引用了未解析的外部符号 _main - Unresolved external symbol _main referenced 错误LNK2019:函数“void __cdecl Padding(int)”中引用的未解析的外部符号___iob_func - error LNK2019: unresolved external symbol ___iob_func referenced in function “void __cdecl Padding(int)” 错误LNK2019:函数“ void __cdecl example2_4(struct _IplImage *)”中引用的未解析的外部符号cvSmooth - error LNK2019: unresolved external symbol cvSmooth referenced in function “void __cdecl example2_4(struct _IplImage *)” 函数“int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ) 中引用的错误 LNK2019 未解析的外部符号 _WinMain@16 - Error LNK2019 unresolved external symbol _WinMain@16 referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM