std::cout" ([email protected]@@[email protected][email protected]@..." /> std::cout" ([email protected]@@[email protected][email protected]@..." /> std::cout" ([email protected]@@[email protected][email protected]@..."/>

I encount follow linker error

unresolved extrenal symbol "class std::basic_ostream > std::cout" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected])"

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.

0 Answers