草庐IT

default_scope

全部标签

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++ - 这个私有(private)变量 "not declared in this scope"怎么样?

我目前正在尝试学习更多有关C++面向对象设计的知识(熟悉Java),但遇到了一些困难。我试图将这个项目放在一起,以在使用SFML构建图形和音频的游戏中学习这些原则。我有以下两个文件。WorldObject.h#ifndefWORLDOBJECT_H#defineWORLDOBJECT_H#include#include#include"ImageManager.h"classWorldObject{private:sf::Sprite_sprite;voidSetImagePath(std::stringpath);sf::SpriteGetGraphic();};#endif世界对象

scope / 作用域(C变量的作用域)

scope/作用域(C变量的作用域)参考:CPrimerPlus第6版第12章存储类别、链接和内存管理目录scope/作用域(C变量的作用域)1.定义2.分类2.1.blockscope/块作用域2.1.1.定义2.1.2.函数的形式参数2.1.3.没有花括号的块2.2.functionscope/函数作用域2.3.functionprototypescope/函数原型作用域2.4.filescope/文件作用域3.总结1.定义描述程序中可以访问identifier(标识符)的区域2.分类scope可以分为四类:2.1.blockscope/块作用域2.1.1.定义block/块是用一块花括号

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++ - 在 scoped_ptr 出现异常时不调用析构函数

我刚刚开始使用C++boost库。我在很多地方读到,当使用scoped_ptr时,即使出现异常,对象也总是被销毁。Theybehavemuchlikebuilt-inC++pointersexceptthattheyautomaticallydeletetheobjectpointedtoattheappropriatetime.Smartpointersareparticularlyusefulinthefaceofexceptionsastheyensureproperdestructionofdynamicallyallocatedobjects.我尝试了以下代码。#includ

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

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

C++ 编译器错误 "was not declared in this scope"

我在尝试编译C++UDP客户端程序时遇到奇怪的编译器错误。g++-oclientUdp.cppClientMain.c-I.-lpthreadInfileincludedfromClientMain.c:1:0:Udp.h:Indestructor‘CUdpMsg::~CUdpMsg()’:Udp.h:103:43:error:‘free’wasnotdeclaredinthisscopeUdp.h:Inmemberfunction‘voidCUdpMsg::Add(in_addr_t,constvoid*,size_t)’:Udp.h:109:34:error:‘malloc’was

c++ - "a struct has public inheritance by default"

“默认情况下结构具有公共(public)继承”这句话的真正含义是什么?为什么下面的代码错误只是因为我在从c派生类d时省略了关键字'public'??structc{protected:inti;public:c(intii=0):i(ii){}virtualc*fun();};c*c::fun(){coutfun();} 最佳答案 意思是structc;structd:c相当于structd:publicc您的代码是一个类,扩展了一个结构:structc;classd:c;相当于classd:privatec;因为class默认有私