From: Mikko Rasa Date: Tue, 3 Jan 2023 15:42:11 +0000 (+0200) Subject: Make Console references static instead of extern X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c77c9fc85ca6b9fc111b1a3d8a84c3903e3dd646;p=libs%2Fcore.git Make Console references static instead of extern This avoids unresolved external errors on MSVC. It's not ideal because every translation unit will have its own copy of the references and initialize them separately, but the overhead for calling the instance accessor function is not too large. --- diff --git a/source/io/console.cpp b/source/io/console.cpp index abb872d..0ac05c6 100644 --- a/source/io/console.cpp +++ b/source/io/console.cpp @@ -68,9 +68,5 @@ Console &Console::instance(Stream s) throw invalid_argument("Console::instance"); } -Console &cin = Console::instance(Console::CIN); -Console &cout = Console::instance(Console::COUT); -Console &cerr = Console::instance(Console::CERR); - } // namespace IO } // namespace Msp diff --git a/source/io/console.h b/source/io/console.h index 1755659..fe777cc 100644 --- a/source/io/console.h +++ b/source/io/console.h @@ -65,9 +65,10 @@ public: static Console &instance(Stream); }; -MSPCORE_API extern Console &cin; -MSPCORE_API extern Console &cout; -MSPCORE_API extern Console &cerr; +// TODO make these inline instead of static when upgrading to C++17. +static Console &cin = Console::instance(Console::CIN); +static Console &cout = Console::instance(Console::COUT); +static Console &cerr = Console::instance(Console::CERR); } // namespace IO } // namespace Msp