0

I encount follow linker error

unresolved extrenal symbol "class std::basic_ostream > std::cout" (?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A)"

when trying to assign std::cout to static constexpr std::stream when using visual stidio 2017 and visual studio 2019. No problem, however, encounters when using gcc.

Following simple testing code could indicate this problem

#include <iostream>

int main()
{
    static constexpr std::ostream* fp = &std::cout;
    *fp << "Hello World!\n";
}

Both expression of

constexpr std::ostream* fp = &std::cout;

or

static std::ostream* fp = &std::cout;

are confirmed to be OK.

My question is:

Is

static constexpr std::ostream* fp = &std::cout;

a legitimate expression. If not, why?

Much thanks.

ASSILI Taher
  • 1,210
  • 2
  • 9
  • 11
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jun 02 '19 at 04:25
  • @KenWhite. I cannot find solution from your link. Tanks anyway – hillyuan Jun 03 '19 at 13:51

0 Answers0