草庐IT

email_from

全部标签

c++ - 什么是 'required from here' 错误

它在我的EclipseProblemsView中。代码编译正常,但有一个错误提示“requiredfromhere”,指向一些boost头文件和行state_dataconstcurrent_state=interlocked_compare_exchange(&state,new_state,old_state);我不喜欢出现错误或警告。有人知道那是什么吗? 最佳答案 此行为是eclipseCDT错误解析器的错误:https://bugs.eclipse.org/bugs/show_bug.cgi?id=108720实际上这个错误

c++ - Const temporary from template type 以及为什么使用 std::add_const?

以下代码摘自cppreference.com.#include#includestructfoo{voidm(){std::coutvoidcall_m(){T().m();}intmain(){call_m();call_m::type>();}但是,当使用VC++Nov2012CTP编译时,输出为Non-cvNon-cv而不是预期的:Non-cvConst另外,下面两个语句有什么区别:call_m();和call_m::type>(); 最佳答案 这似乎是MSVC的一个错误。使用T()形式的表达式(就标准而言,这是一种显式类型转

C++11/14 : How to remove a pointer-to-member from a type?

在C++11或C++1y/14中:给定一个TC::*形式的指向成员类型的值,我想得到指向类型例如:#includeusingnamespacestd;structT1{staticvoidf(){coutstructV;templatestructV{staticconstexprT1U1::*pm=&U1::x;};templatestructV{staticconstexprT2U2::*pm=&U2::x;};templatevoidf(Wpm){typedef???T;T::f();}intmain(){f(V::pm);f(V::pm);}有没有办法做到这一点?上面的???是

c++ - 使用 boost::enable_shared_from_this 时出现不完整的类型错误

在下一行classSymbol:publicboost::enable_shared_from_this{我得到错误:错误:不完整类型的无效使用structboost::enable_shared_from_this/usr/include/boost/smart_ptr/shared_ptr.hpp:63:错误:声明structboost::enable_shared_from_this知道为什么我会收到此错误。Symbol是一个抽象类(如果重要的话) 最佳答案 哎呀。错误是因为我没有包含定义enable_shared_from_

c++ - enable_shared_from_this 的双重继承

我有一个对象(Z),它派生自另外两个对象(A和B)。A和B都派生自enable_shared_from_this,分别enable_shared_from_this和enable_shared_from_this.我当然会调用shared_from_this()在Z上。当然,编译器将其报告为不明确。我的问题是:从enable_shared_from_this继承两次是否安全?或者它会创建两个独立的引用计数(不好!)如果不安全,我该如何解决?注意:我发现了另一个问题badweakpointerwhenbaseandderivedclassbothinheritfromboost::ena

c++ - enable_shared_from_this(c++0x): what am I doing wrong?

我只是在研究即将推出的新C++标准中的智能指针。但是我没有掌握shared_from_this函数的用法。这是我所拥有的:#include#includeclassCVerboseBornAndDie2:publicstd::enable_shared_from_this{public:std::stringm_Name;CVerboseBornAndDie2(std::stringname):m_Name(name){std::coutp=vbad->shared_from_this();}并在行中抛出std::bad_weak_ptr异常std::shared_ptrp=vbad-

c++ - 使用可变参数模板重载函数模板 : Intel c++ compiler version 18 produces different result from other compilers. intel 错了吗?

考虑以下代码片段:templateclassA,typename...Ts>inta(Aarg){return1;//Overload#1}templateinta(Aarg){return2;//Overload#2}templatestructS{};intmain(){returna(S());}在使用模板类的实例调用函数a时,我希望编译器选择更特殊的函数重载#1。根据compilerexplorer、clang、gcc和17版之前的英特尔实际上会选择重载#1。相反,后来的英特尔编译器版本(18和19)选择重载#2。是代码定义不正确还是最新的英特尔编译器版本有误?

c++ - LLVM 字符串值对象 : How can I retrieve the String from a Value?

当从现有的AST构建IR时,我的AST有一些字符串值(在编译时它们是从std::string构建的)并且我想将它们安全地设置为llvm::Value用作表达式的一部分。在这种情况下,我不需要在运行时绑定(bind)字符串,因为字符串值仅用于在编译时将内容解析为变量、函数或类(该语言不支持native字符串类型)。什么是将我的字符串内容保持为llvm::Value并且仍然能够在编译的后期阶段检索它的最佳方法(当构建嵌套表达式时)?更具体地说,如果我将llvm::Value设置为:llvm::Value*v=llvm::ConstantArray::get(llvmContext,mySt

c++ - libstdc++ : DSO missing from command line

我在执行gtkmm应用程序的makefile时遇到问题。我已经实现了一个简单的解决方案,但是,我收到以下错误:g++-Wall-std=c++11pkg-configgtkmm-3.0--cflags-cmain.cppccmain.opkg-configgtkmm-3.0--libs-omain/usr/bin/ld:main.o:undefinedreferencetosymbol'__gxx_personality_v0@@CXXABI_1.3'/usr/lib/x86_64-linux-gnu/libstdc++.so.6:erroraddingsymbols:DSOmissi

c++ - enable_shared_from_this 和堆栈上的对象

有没有办法阻止shared_from_this()调用堆栈分配的对象?基类列表中的enable_shared_from_this是类用户的强指标,但有没有办法强制正确使用?示例代码:classC:publicenable_shared_from_this{public:shared_ptrmethod(){returnshared_from_this();}};voidfunc(){Cc;shared_ptrptr=c.method();//exceptioncomingfromshared_from_this()} 最佳答案 因此