を使用しているときに 'T'から 'const char *'への変換がありません。コンソールとファイルの両方にstuffを出力する演算子< <チェーンを使用するクラスがあります。同時に。行が壊れたときはいつでもそれをフラッシュする必要があります。これは、定義されたendl(\ nで置き換えられます)で起こります。このコードは動作せず、多くのエラーを吐き出します(Tからconst char *への変換はありません)。なにが問題ですか?std :: is_same <T、const char *> ::値
#pragma once
#include <iostream>
#include <fstream>
/*class declaration*/
template <typename T>
inline Logger & Logger::operator<<(const T &a)
{
if (debug::enabled)
{
std::cout << a;
file << a;
if (this->previousLineBroken)
{
std::cout << std::flush;
file << std::flush;
this->previousLineBroken = false;
}
if (std::is_same<T, const char*>::value) {
this->previousLineBroken = (a == debug::endl);
}
return *this;
}
}
削除のconst(定数T & a)はちょうどより多くのエラーと物事が悪化します。
UPD: previousLineBrokenはboolで、debug :: endlはconst char * = "\ n"です。
//debug.h
#pragma once
#define logger *logPtr
#include "Classes.h"
#include "logger.h"
namespace debug
{
static const char* endl = "\n";
static const bool enabled = true;
}
using debug::endl;
'previousLineBroken'と' debug :: endl'の種類は何ですか? –
@static_cats boolとconst char * – AdmiralMyxtaR