草庐IT

non-passphrase-protected

全部标签

c++ - MSVC : modifiers not allowed on non-memberfunction

我在linux下编写了一个信号/插槽库(Codeprojectarticlehere),同时使用Clang3.5和GCC4.9进行编译。它在两个编译器上编译时都没有警告(也在3.4版和4.8版上)。当我完成所有工作并将文章发布到网上时,没过多久我就收到投诉说它不能在MSVC上工作。(VisualStudioExpress2013?对不起,我对版本控制系统不熟悉。)我把它安装在虚拟机中自己看了一下,发现它不会编译以下内容:templatestructRemoveCV;templatestructRemoveCV{usingType=R(Args...);};templatestructR

c++ - 从基类的静态模板方法中调用继承类的 protected 构造函数失败

我有一个组件类,它定义了一般情况下应该如何创建Component的静态模板方法:classComponent{protected:uint32_tid;Component(uint32_tid):id(id){}templatestaticT*createComponent(){//contentherenotrelevantreturnnewT(someParameter);}};然后是一个实现,例如一个Button。这个类的构造函数不能直接使用,而是有一个调用Component::createComponent模板函数的静态方法。classButton:publicComponen

c++ - 如何从友元函数访问 protected 构造函数?

我创建了一个类,我想强制任何试图构建对象的人使用unique_ptr。为此,我考虑声明构造函数protected并使用返回unique_ptr的friend函数。所以这是我想做的一个例子:templateclassA{public:friendstd::unique_ptr>CreateA(intmyarg);protected:A(intmyarg){}};templatestd::unique_ptr>CreateA(intmyarg){//SinceIdeclaredCreateAasafriendIthoughtI//wouldbeabletodothatreturnstd::

c++ - libc++ 与 VC++ : Can non-UTF conversions be done with wstring_convert?

C++11的std::wstring_convert效果很好*用于标准UTF-8UTF-16/UCS2/UCS4转换。但是,当我尝试使用不是来自的构面实例化wstring_convert或wbuffer_convert时,它没有按预期工作://worksasexpectedstd::wstring_convert>ucs4conv;//Now,byanalogy,Iwanttotrythis:std::wstring_convert>gbconv(newstd::codecvt_byname("zh_CN.gb18030"));Clang++错误提示“在~wstring_convert

c++ - 隐式转换 : const reference vs non-const reference vs non-reference

考虑这段代码,structA{};structB{B(constA&){}};voidf(B){cout这compilesfine,运行良好。但是,如果我将f(B)更改为f(B&),它doesn'tcompile.如果我写f(constB&),它又是compilesfine,运行良好。原因和道理是什么?总结:voidf(B);//okayvoidf(B&);//errorvoidf(constB&);//okay对于每种情况,我想听听语言规范中的原因、基本原理和引用资料。当然,函数签名本身并没有错。A隐式转换为B和constB&,但不会转换为B&,这会导致编译错误。

c++ - C++中 protected 和私有(private)派生之间的区别是什么

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Differencebetweenprivate,publicandprotectedinheritanceinC++在C++中派生为protected或private有什么区别?我想不通,因为两者似乎都限制从派生类对象访问基类成员

c++ - 为什么不能实例化带有 "non const"复制构造函数的对,而没有实例化一对是可能的?

假设您有以下类(class):structA{A(){}A(A&)=delete;};intmain(){std::pairp1;return0;}以下代码将无法编译(使用-std=c++11和g++)并出现以下错误:/usr/include/c++/5/bits/stl_pair.h:Ininstantiationof‘structstd::pair’:test.cpp:13:23:requiredfromhere/usr/include/c++/5/bits/stl_pair.h:127:17:error:‘constexprstd::pair::pair(conststd::pa

c++ - 错误 : invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector<bool>::reference {aka std::_Bit_reference}’

为什么我会收到错误:从类型为“std::vector::reference{akastd::_Bit_reference}”的右值对类型为“bool&”的非常量引用进行无效初始化?vector>vis;bool&visited(intx,inty){returnvis[x][y];//error}据我所知,vector中的operator[]返回引用,所以它应该是一个左值,但它不起作用。我应该怎么做才能让它发挥作用? 最佳答案 那是因为std::vector不是它看起来的样子。std::vector有一个特化与类型bool-它是空间

c++ - 铿锵错误 : non-type template argument refers to function that does not have linkage -- bug?

我有一些非常简单的(C++11)代码,最新的clang(version3.4trunk187493)无法编译,但GCC编译正常。代码(下面)实例化函数模板foo使用局部函数类型Bar然后尝试将其地址用作类模板Func的非类型模板参数:templatestructFunc{};templateexterninlinevoidfoo(){usingFoo=Func>;}intmain(){structBar{};//function-localtypefoo();return0;}clang发出以下错误:error:non-typetemplateargumentreferstofunct

c++ - 派生类中 protected 成员函数地址不可访问

#includeclassA{protected:voidfoo(){}};classB:publicA{public:voidbar(){std::cout这里我试图获取基类的protected成员函数的地址。我收到此错误。main.cpp:Inmemberfunction‘voidB::bar()’:main.cpp:5:error:‘voidA::foo()’isprotectedmain.cpp:13:error:withinthiscontextmake:***[all]Error1将foo更改为公共(public)工程。打印&B::foo也可以。能否请您解释一下为什么我们无