So, I want to get the console log to a file; that works fine, the problem lies when I tried to extend it to allow more inputs, and I don’t seem to know why.
Engine.h:
#pragma once
#ifdef ENGINE_EXPORTS
#define ENGINE_API __declspec(dllexport)
#else
#define ENGINE_API __declspec(dllimport)
#endif
// Logging functions
template <typename T, typename... Args>
ENGINE_API void EngineLog(const T& first, const Args&... args); // this started causing problems.
// Other unrelated functions
^ This is how I am handeling my header file.
In the Engine.cpp file; this is the function that does the logging:
//top of Engine:
#include "Engine.h"
template <typename T, typename... Args>
void EngineLog(const T& first, const Args&... args) {
std::ostringstream oss;
oss << first;
((oss << ' ' << args), ...);
std::string strMessage = oss.str();
std::cout << strMessage << std::endl;
if (log_file.is_open()) {
log_file << strMessage << std::endl;
}
else {
std::cout << "Failed to log to file." << std::endl;
}
}
I tried anything that came to mind when it came to fixing this, but I never managed to find why it wouldn’t compile, I hope this is obvious enough for anyone to help as this had me stumped for a while, and I would like to learn what I did wrong so I can never make the mistake again.
Maybe, there is a better way of doing dlls, but I am unaware of any other way…
Anyways; I Expect it to work in the Application project as follows:
EngineLog(38," <-- Numbers --> ", double, " ", integer);
Before I tried to expand it to accept arguments, it worked fine.
and I don’t know if it was something I tried to do, but I started getting errors in other functions in the Engine.h, about my “nested create directory” script accepting strings being invalid, but I can always just change that, that is unrelated to my current problem.
Kjajidlah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.