我在gdb中启动程序时遇到此错误:
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Traceback (most recent call last):
File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'
Run Code Online (Sandbox Code Playgroud)
谷歌发现了这个错误报告:http://osdir.com/ml/debian-gcc/2014-02/msg00061.html
这个错误报告列表使用python print sys.pathgdb提示符上的命令.但是,当我尝试在gdb提示符上使用任何python时,会发生这种情况:
(gdb) python print sys.path
File "<string>", line 1
print sys.path
^
SyntaxError: invalid syntax
Error while executing Python code.
(gdb) python print "Hello"
File "<string>", line 1
print "HellO"
^
SyntaxError: invalid syntax
Error while executing Python code.
Run Code Online (Sandbox Code Playgroud)
我正在使用Ubuntu 14.04 LTS,相关版本信息:
$ gcc --version
gcc …Run Code Online (Sandbox Code Playgroud) 如果内存被分配malloc(而不是new)并且对象被移动到该内存中,那么该C++是否有效?假设我为n个类型的对象数组分配内存T,并且我有一系列n类型的对象T我想要移入其中,这是有效的:
T* next = (T *)malloc(n*sizeof(T));
T* t = std::begin(my_range);
while (we still have more Ts) {
*next = std::move(*t);
++next;
++t;
}
Run Code Online (Sandbox Code Playgroud)
这似乎有效,但我很好奇它为什么会这样,因为我们从未在我们移动到的已分配内存中新建对象.
我的猜测是放置新的是正确的方法:
while (we still have more Ts) {
new (next) T(*t);
++next;
++t;
}
Run Code Online (Sandbox Code Playgroud)
但我想知道为什么第一个是不正确的,如果是的话,如果它只是运气或因为T恰好是POD.
这段代码实际上有效:
class Abstract {
virtual auto foo() -> int = 0;
};
class Concrete: public Abstract {
int foo() { cout << "blah!" << endl; return 1; }
} instance;
Run Code Online (Sandbox Code Playgroud)
我知道函数被破坏并链接到相同的函数签名,但这种混合在C++ 14中实际上是合法的吗?
让我们Base和Derived与数据成员的类:
class Base {
public:
Base(int i):f(i) { }
virtual void print() { cout << "base " << f << endl; }
int f;
};
class Derived: public Base {
public:
Derived(int i):Base(0),g(i) { }
void print() { cout << "derived " << g << endl; }
int g;
};
Run Code Online (Sandbox Code Playgroud)
现在创建的一些实例Base,并Derived在堆,并将它们存储在boost::ptr_vector:
int main(int argc, char *argv[])
{
boost::ptr_vector<Base> v;
v.push_back(new Derived(1));
v.push_back(new Base(2));
v.push_back(new Base(3));
v.push_back(new Derived(4));
Run Code Online (Sandbox Code Playgroud)
打印所有对象:
for (std::size_t …Run Code Online (Sandbox Code Playgroud) 我正在使用 GetAdaptersAddresses 查找计算机的所有 IPv6 地址。
我想区分全局地址和RFC4941临时地址(RFC4941也称为“隐私扩展”)。
这个答案建议使用地址的首选生命周期来查找临时地址,因为它的生命周期较短。除了这是一个拼凑之外,它在我的机器上也不起作用(使用 Windows 7)。这是 netsh interface ipv6 show address 的输出
Addr Type DAD State Valid Life Pref. Life Address
--------- ----------- ---------- ---------- ------------------------
Public Preferred 1h58m15s 16m36s xxxx:xx:xxxx:2000:71e7:xxxx:xxxx:f45b
Temporary Preferred 1h58m15s 16m36s xxxx:xx:xxxx:2000:8479:xxxx:xxxx:a70a
Other Preferred infinite infinite fe80::71e7:xxxx:xxxx:f45b%19
Run Code Online (Sandbox Code Playgroud)
您可以看到两个地址的生命周期是相同的。
那么,如何才能获取临时地址的标志,或者更挑衅地问,ipconfig 或 netsh 如何知道它们正在使用的 API 是什么?
我有一个支持A2DP播放音频的蓝牙设备(耳机).我一直在与iPhone和Android配对,而且两种来源的音质都非常差.
我怀疑该设备仅支持SBC编解码器,但不支持Mp3.或者,如果它是MP3,只有极低的比特率.制造商仅支持A2DP,但不支持哪种编解码器.
如何确定支持哪些编解码器?是否有一种协议嗅探器,我可以在我的手机或我的电脑上使用,并询问设备,以获得它支持的确切答案?
在C++ 11中,成员函数上的constexpr意味着const.这在C++ 14中有所改变.
我有一些代码,其成员函数应该是constexpr,但不能是const,所以如果用std c ++ 14或更高版本编译,我希望它是constexpr.一种方法是:
class Foo {
#if _cplusplus >= 201402L
constexpr
#endif
int baz(const Bar& bar);
};
Run Code Online (Sandbox Code Playgroud)
是否有更好的方式表达这一点,最好没有预处理器?
考虑以下代码:
#include <boost/serialization/nvp.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
class Foo{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int)
{
ar & BOOST_SERIALIZATION_NVP(i);
}
int i;
Foo():i(0){}
public:
Foo(int k):i(k){}
};
int main(int argc, char *argv[])
{
std::vector< Foo> f;
f.push_back(Foo(12));
std::ofstream os("path");
boost::archive::xml_oarchive oa(os);
oa << boost::serialization::make_nvp("f", f);
os.close();
std::vector<Foo> g;
std::ifstream is("path");
boost::archive::xml_iarchive ia(is);
ia >> boost::serialization::make_nvp("f", g);
}
Run Code Online (Sandbox Code Playgroud)
在序列化 Foos 向量时效果很好。但是,如果我尝试序列化 Foos 的映射,它会在私有默认构造函数上失败:
std::map<std::string, Foo> f;
f.insert(std::make_pair("hello", Foo(12)));
std::ofstream os("path");
boost::archive::xml_oarchive oa(os);
oa << boost::serialization::make_nvp("f", …Run Code Online (Sandbox Code Playgroud)