草庐IT

bad_name

全部标签

c++ - 即使正确使用 make_shared,shared_from_this() 也会导致 std::bad_weak_ptr

我正在使用独立的Asio和C++11创建一个C++服务器应用程序,但遇到错误,这就是我寻求帮助的原因。错误在类里面worker_thread,在通话期间shared_from_this(),一个bad_weak_ptr引发异常,导致程序崩溃。布局类(class)connection_manager创建并存储std::shared_ptr类型的对象在std::vector里面容器类(class)worker_thread继承自std::enable_shared_from_this.类(class)worker_thread创建std::shared_ptr类型的对象.类(class)c

C++ 风格约定 : Parameter Names within Class Declaration

我是一个相当新的C++程序员,我想听听支持和反对在类声明中命名参数的争论。这是一个例子:Student.h#ifndefSTUDENT_H_#defineSTUDENT_H_#includeusingnamespacestd;classStudent{private:stringname;unsignedintage;floatheight,GPA;public:Student(string,unsignedint,float,float);voidsetAge(unsignedint);};#endif/*STUDENT_H_*/对比#ifndefSTUDENT_H_#defineS

c++ - 来自 Xcode 8.3.2 : Non-portable path to file - specified path differs in case from file name on disk 的错误警告

出于某种原因,我的代码库突然开始收到数以千计的此类警告。但到目前为止,所有有问题的文件和路径都是完全正确的,与我在磁盘上看到的与Finder相匹配。他们是不是在暗地里另有幕后?当问题实际上并不存在时,为什么Xcode会生成这些警告?尽管http://stackoverflow.com/questions/43067017/non-portable-path-to-file-file-h-specified-path-differs-in-case-from-file-na是关于相同的警告,在这种情况下我已经验证导入路径与磁盘上的文件名匹配。 最佳答案

c++ - 为什么 injected-class-name 有时不被视为类模板中的模板名称?

SourceInthefollowingcases,theinjected-class-nameistreatedasatemplate-nameoftheclasstemplateitself:itisfollowedbyitisusedasatemplateargumentthatcorrespondstoatemplatetemplateparameteritisthefinalidentifierintheelaboratedclassspecifierofafriendclasstemplatedeclaration.所以我尝试检查所有3种情况(另外在基本歧义的情况下,尽管我

c++ - 为什么 std::bad_cast 被 boost::locale 抛出?

我试图了解如何使用boost::locale来比较忽略大小写和变体的字符串。我直接尝试了Boost文档中的代码:http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/collation.htmlboost::locale::generatorgen;std::localevLocale=gen("");std::wstringa=L"Façade",b=L"facade";//Followingwillthrowbad_castbooleq=std::use_facet>(vLocale).compare(boost::lo

c++ - 自定义异常层次结构。来自 std::exception 和 std::bad_alloc 的可怕钻石

我在自己的异常层次结构中遇到继承问题。Exception类具有很好的功能(回溯、日志记录等),因此它是我处理任何异常的基类。正如我在许多网页中看到的那样,它继承自std::exception。此外,我正在使用一个单元测试框架来报告任何std::exception被意外抛出。但归根结底,这只是为了方便。然后,我有一个新的OutOfMemoryException类,它将由自定义new_handler抛出。该类继承自Exception,但也继承自std::bad_alloc以兼容现有代码。我猜这更重要,因为new将不再抛出std::bad_alloc。这里的问题很明显:因为std::bad_

c++ - Visual C++ 2010 拒绝在调试时显示 std::string 值。显示 <Bad Ptr>

我有一种奇怪的感觉,好像这是最近才出现的问题,并且发生在两台不同的计算机上。当我调试并尝试查看来自STL的std::string的值时,它显示为值。它说它的大小是15,容量是一些乱码。数组值本身都显示CXX0030:错误:无法计算表达式。这非常令人沮丧,如果我在字符串上调用c_str并将其分配给char*或在需要时使用监视表达式,我仍然可以在调试时访问字符串值,但它非常乏味并且让生活变得非常艰难连续3天调试复杂问题。其他STL容器的内容显示得很好。这发生在两台不同计算机上的多个项目上,我很确定我已经为该项目设置了所有调试选项。没有优化,肯定会生成调试信息。

c++ - G++ 4.4.7 中的 "names the constructor, not the type"

我有以下简单的C++代码:#includeclassA{public:A(inty):x(y){}A&operator=(constA&rhs);intx;};A::A&A::operator=(constA&rhs){this->x=rhs.x;return*this;}intmain(int,char**){Aa1(5);Aa2(4);printf("a2.x==%d\n",a2.x);a2=a1;printf("a2.x==%d\n",a2.x);return0;}第11行,A的operator=()函数的定义所在,格式不正确......或者,至少,我相信是这样。正如预期的那样,

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - 为什么将数组作为 "int *& name"传递?

我得到了一个(C++)代码,其中使用数组传递voidfun(int*&name){...}但这背后的想法是什么?我猜它的意思是“一个引用数组”,但是当你只传递一个指向第一个元素的指针时就没问题了,不是吗?那么这样做的动机是什么? 最佳答案 该函数接收对指针的引用。这意味着该函数不仅可以修改name指向的int,还可以修改自身指针函数调用也将在外部可见。例子:#includeint*allocate(){returnnewint();}voiddestroy(int*&ptr){deleteptr;ptr=NULL;}intmain(