Accessing a function, defined in the encapsulating structure, in the nested template function

4 weeks ago 16
ARTICLE AD BOX

Inner structs are mostly like regular struct, you need a instance of LoggingClass to access its non static members.

Demo providing one:

template <typename... Ts> struct FAEWE_LOG_THREAD { FAEWE_LOG_THREAD(LoggingClass& c, [[maybe_unused]]const char * formatString, [[maybe_unused]]Ts &&... logArguments, const std::source_location & sourceLocation = std::source_location::current() ) { ////////////////////////////////////////////////////////////// // How to access <getInstrumentsId()> defined in LoggingClass? std::cout << sourceLocation.function_name() << ": InstrumentsId from LoggingClass:" << c.getInstrumentsId() << std::endl; ////////////////////////////////////////////////////////////// } FAEWE_LOG_THREAD([[maybe_unused]]LoggingClass& c, [[maybe_unused]]bool fallbackToServer, [[maybe_unused]]const char * formatString, [[maybe_unused]]Ts &&... logArguments, [[maybe_unused]]const std::source_location & sourceLocation = std::source_location::current() ) { } }; template <typename... Ts> FAEWE_LOG_THREAD(LoggingClass& c, const char *, Ts &&... ) -> FAEWE_LOG_THREAD<Ts...>; template <typename... Ts> FAEWE_LOG_THREAD(LoggingClass& c, bool, const char *, Ts &&... ) -> FAEWE_LOG_THREAD<Ts...>; // [..] auto Faewe::demo() -> void { FAEWE_LOG_THREAD(*this, "Pi=%.3f", 3.141 ); FAEWE_LOG_THREAD(*this, true, "Euler's=%.3f", 2.718 ); std::cout << "InstrumentsId in LoggingClass=" << this->getInstrumentsId() << std::endl; }

Demo

Jarod42's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article