草庐IT

defaulted

全部标签

c++ - "vtable"链接器错误(涉及带有 "=default"的虚拟析构函数)- Clang 3.1 中的潜在错误?

我的代码中出现链接器错误。我已将其精确定位为以下最基本的要点。这段代码给出了链接器错误"vtableforFoo",referencedfrom:Foo::Foo()classFoo{public:Foo();virtual~Foo()=default;};Foo::Foo(){}但是这段代码没有给出任何错误:classFoo{public:Foo();virtual~Foo(){}};Foo::Foo(){}为什么?我认为=default基本上应该和那些空方括号做同样的事情。更新:我正在使用“AppleLLVM编译器4.1”,它是Xcode4.5.2的一部分。这可能是这个编译器中的错

c++ - 模板函数 : default construction without copy-constructing in C++

考虑structC{C(){printf("C::C()\n");}C(int){printf("C::C(int)\n");}C(constC&){printf("copy-constructed\n");}};还有一个模板函数templatevoidfoo(){//default-constructatemporaryvariableoftypeT//thisiswhatthequestionisabout.Tt1;//willbeuninitializedfore.g.int,float,...Tt2=T();//willcalldefaultconstructor,thenco

c++ - 将代码从 C++03 迁移到 C++11 : should I be cautious about the implicit default move constructor?

我有一个代码库,我想从C++03切换到C++11。据我所知,某些类将通过具有隐式默认移动构造函数(以及随之而来的移动赋值运算符)而从更改中受益。虽然我完全同意(我什至认为这是一件好事),但我有点担心这种隐式构造函数可能对我拥有的某些不可复制类产生的影响。我举的一个例子是一个类,它包装了libiconv的iconv_t句柄以利用RAII。更明确地说,类如下:classiconv_wrapper{public:iconv_wrapper():m_iconv(iconv_open()){}~iconv_wrapper(){iconv_close(m_iconv);}private://Not

c++ - 如何在模板元编程中使用 'default' 值

我面临以下问题:我有一些通用容器,能够对类型执行一些操作。为简单起见,这些操作在需要时是线程安全的。并且,请求意味着容器中的类型具有typedefstd::true_typeneeds_thread_safety;。structthread_safe_item{typedefstd::true_typeneeds_thread_safety;/**/};structthread_unsafe_item{typedefstd::false_typeneeds_thread_safety;/**/};templatecontainer{/*somealgorithms,thatarestd

c++ - 谷歌模拟 : "no appropriate default constructor available"?

将VisualStudio2010C++与googlemock结合使用。我正在尝试使用我创建的模拟,但在线上遇到编译器错误:EmployeeFakeemployeeStub;错误是:1>c:\someclasstests.cpp(22):errorC2512:'MyNamespace::EmployeeFake':noappropriatedefaultconstructoravailable假员工:classEmployeeFake:publicEmployee{public:MOCK_CONST_METHOD0(GetSalary,double());}员工:classEmploy

c++ - 何时使用 =default 与 =delete

据我了解,这些语义仅用于复制构造函数、移动构造函数、复制赋值、移动赋值和析构函数。使用=delete用于禁止使用其中一项功能,即=default如果您想向编译器明确说明在何处使用这些函数的默认值,则使用它。在制作类(class)时使用这些关键字的最佳做法是什么?或者更确切地说,在开发类(class)时我如何记住这些?例如,如果我不知道我是否会使用这些功能之一,最好用delete禁止它。或允许并使用default? 最佳答案 好问题。同样重要的是:哪里使用=default和=delete.我对此有一些有争议的建议。它与我们所有人(包括

c++ - "= default"是否允许离线实现?

通常我会在header中看到=default语法。我的理解是,这与函数在header中明确实现是一样的,请参见下面的Foo。Foo.h#pragmaonceclassFoo{public:Foo()=default;Foo(constFoo&other)=default;};纯粹出于好奇,=default可以在源文件中使用如下吗?栏.h#pragmaonceclassBar{public:Bar();Bar(constBar&other);};酒吧.cpp#include"Bar.h"Bar::Bar()=default;Bar::Bar(constBar&)=default;据我所知

c++ - 为什么 =default on operator= 在有 const 成员时编译?

classFoo{public:Foo&operator=(constFoo&)=default;private:constinti=0;};为什么=default在那里被允许?它编译没有错误。我认为=default应该失败,因为它不可能分配给const变量?到底发生了什么? 最佳答案 当无法生成该函数时(就是这种情况),=default会将其生成为=deleted。如果您尝试使用该赋值运算符,您的编译器应该produceanerror. 关于c++-为什么=defaultonopera

鸿蒙开发解决hvigor ERROR: Failed :entry:default@ProcessLibs...

文章目录项目场景:问题描述原因分析:建议的解决方案总结HarmonyOSArkTS项目场景:项目无法在真机上运行。报错hvigorERROR:Failed:entry:default@ProcessLibs…hvigorERROR:2filefoundin‘lib/arm64-v8a/libagccrypto.so’.Thismaycauseunexpectederrorsatruntime.问题描述报错问题如下:hvigorERROR:Failed:entry:default@ProcessLibs…hvigorERROR:2filefoundin‘lib/arm64-v8a/libagcc

C++ 编译器错误 c4430 "c++ doesnt support default int"

这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭9年前。您好,我正在尝试定义一个名为USHORT的别名。//Demonstratestypedefkeyword#includetypedefunsignedshortintUSHORT;//typedefdefinedmain(){USHORTWidth=5;USHORTLength;Length=10;USHORTArea=Width*Length;std::