gpt4 book ai didi

c++ - std::ios_base::ios_base(const std::ios_base) 是私有(private)的

转载 作者:行者123 更新时间:2023-11-30 02:42:36 24 4
gpt4 key购买 nike

FatalMessageAssembler是一个通过 << 将消息收集到内部字符串流变量的类运算符(operator)。它打印 result 的消息变量并通过 += 终止应用程序运算符(operator)。 (我有理由不把它放在一个函数中)

标题:

class FatalMessageAssembler
{
public:
FatalMessageAssembler();
std::stringstream contents;
void operator+=(FatalMessageAssembler& result);
};
template<typename msg_type> FatalMessageAssembler& operator<<(FatalMessageAssembler& target,const msg_type msg);
namespace NLog
{
extern FatalMessageAssembler assembler;
}

来源:

FatalMessageAssembler::FatalMessageAssembler()
{

}
FatalMessageAssembler NLog::assembler=FatalMessageAssembler();
template<typename msg_type> FatalMessageAssembler& operator<<(FatalMessageAssembler& target, const msg_type msg)
{
target.contents<<msg;
return target;
}
void FatalMessageAssembler::operator+=(FatalMessageAssembler& result)
{
qFatal(result.contents.str().c_str());
result.contents.str("");//I'm not sre if qFatal() can be handled not to terminate app
result.contents.clear();
}

这会产生一个错误 std::ios_base::ios_base(const std::ios_base) is private .我 didn't forget reference in return type.

完整日志:

06:36:41: Running steps for project tsl...
06:36:41: Configuration unchanged, skipping qmake step.
06:36:41: Starting: "/usr/bin/make"
g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I../tsl -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../tsl -I. -o servicelogger.o ../tsl/servicelogger.cpp
In file included from /usr/include/c++/4.8/ios:42:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/qt4/QtCore/qlist.h:50,
from /usr/include/qt4/QtCore/qobject.h:50,
from /usr/include/qt4/QtCore/QObject:1,
from ../tsl/servicelogger.h:5,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/bits/ios_base.h: In copy constructor 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)':
/usr/include/c++/4.8/bits/ios_base.h:786:5: error: 'std::ios_base::ios_base(const std::ios_base&)' is private
ios_base(const ios_base&);
^
In file included from /usr/include/c++/4.8/ios:44:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/qt4/QtCore/qlist.h:50,
from /usr/include/qt4/QtCore/qobject.h:50,
from /usr/include/qt4/QtCore/QObject:1,
from ../tsl/servicelogger.h:5,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from ../tsl/servicelogger.h:8:0,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/sstream: In copy constructor 'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)':
/usr/include/c++/4.8/sstream:502:11: note: synthesized method 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)' first required here
class basic_stringstream : public basic_iostream<_CharT, _Traits>
^
In file included from /usr/include/c++/4.8/ios:43:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/qt4/QtCore/qlist.h:50,
from /usr/include/qt4/QtCore/qobject.h:50,
from /usr/include/qt4/QtCore/QObject:1,
from ../tsl/servicelogger.h:5,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/streambuf: In copy constructor 'std::basic_stringbuf<char>::basic_stringbuf(const std::basic_stringbuf<char>&)':
/usr/include/c++/4.8/streambuf:802:7: error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]' is private
basic_streambuf(const basic_streambuf& __sb)
^
In file included from ../tsl/servicelogger.h:8:0,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/sstream:64:11: error: within this context
class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
^
/usr/include/c++/4.8/sstream: In copy constructor 'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)':
/usr/include/c++/4.8/sstream:502:11: note: synthesized method 'std::basic_stringbuf<char>::basic_stringbuf(const std::basic_stringbuf<char>&)' first required here
class basic_stringstream : public basic_iostream<_CharT, _Traits>
^
In file included from ../tsl/servicelogger.cpp:2:0:
../tsl/servicelogger.h: In copy constructor 'FatalMessageAssembler::FatalMessageAssembler(const FatalMessageAssembler&)':
../tsl/servicelogger.h:39:7: note: synthesized method 'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)' first required here
class FatalMessageAssembler
^
../tsl/servicelogger.cpp: At global scope:
../tsl/servicelogger.cpp:47:61: note: synthesized method 'FatalMessageAssembler::FatalMessageAssembler(const FatalMessageAssembler&)' first required here
FatalMessageAssembler NLog::assembler=FatalMessageAssembler();
^
../tsl/servicelogger.cpp: In member function 'void FatalMessageAssembler::operator+=(FatalMessageAssembler&)':
../tsl/servicelogger.cpp:55:41: warning: format not a string literal and no format arguments [-Wformat-security]
qFatal(result.contents.str().c_str());
^
make: *** [servicelogger.o] Error 1
06:36:46: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project tsl (kit: Desktop)
When executing step "Make"
06:36:46: Elapsed time: 00:05.

最佳答案

FatalMessageAssembler NLog::assembler=FatalMessageAssembler();

这是导致错误的关键行。您无法复制流,因此您无法复制 FatalMessageAssemblers1。但是,实际上不需要临时初始化。

FatalMessageAssembler NLog::assembler;

还应该适本地初始化汇编程序

1) 您的类的移动构造函数未隐式声明,因为成员之一的类型 stringstream 不可复制。

关于c++ - std::ios_base::ios_base(const std::ios_base) 是私有(private)的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26945465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com