草庐IT

object-reference

全部标签

c++ - 为什么 std::move() 没有 _Remove_reference 就不能工作?

如您所知,_Remove_reference的存在是为了将T&转换为T或将T&&转换为T。我怀着一种玩乐的心情写了下面的代码,它根本没有像我预期的那样工作,但不知道为什么。templatestruct_Remove_reference{//removereferencetypedef_Ty_Type;staticvoidfunc(){cout//struct_Remove_reference//{//removereference//typedef_Ty_Type;//staticvoidfunc(){cout//struct_Remove_reference//{//removerv

c++ - std::list of objects 效率

假设您有某个类的std::list。您可以通过两种方式制作此列表:1)std::listmyClassList;MyClassmyClass;myClassList.push_front(myClass);使用此方法,当您将对象传递给列表时,复制构造函数将被调用。如果该类有很多成员变量,并且您多次进行此调用,它的成本可能会很高。2)std::listmyClassList;MyClass*myClass=newMyClass();myClassList.push_front(myClass);这个方法不会调用类的复制构造函数。我不太确定在这种情况下会发生什么,但我认为该列表将创建一个新

c++ - if ('fstream object' ) 如何根据文件是否打开返回真值或假值?

我很好奇fstreamclass是如何简单地返回一个true或false值的将对象的名称放在条件语句中。例如……std::fstreamfileStream;fileStream.open("somefile.ext");if(!fileStream)//Howdoesthiswork?std::cout我问这个是因为如果我以类似的方式使用它,我希望我自己的类返回一个值。 最佳答案 它并不是真的等于真或假,而是它重载了!运算符以返回其状态。参见http://www.cplusplus.com/reference/iostream/i

gpt支持json格式的数据返回(response_format: ‘json_object‘)

Api.h5.chatCreateChatCompletion({model:'gpt-3.5-turbo-1106',token:'sk-f4fe8b67-fcbe-46fd-8cc9-fd1dac5d6d59',messages:[{role:'user',content:'使用json格式返回十二生肖,包含中文名和英文名,[{id:"1",enName:"",cnName:""}]',},],params:{n:1,response_format:{type:'json_object'},},}).then((res)=>{if(res.code===200){console.log(r

c++ - QMediaPlayer undefined reference 链接器错误

我安装了Qt5,但由于Qt5不支持Phonon,我不得不使用其他东西,所以我决定使用QtMultimedia。.pro文件:QT+=coreguiCONFIG+=mobilityMOBILITY+=multimedia.cpp代码:#include"mainwindow.h"#include"ui_mainwindow.h"#include#include#include...voidMainWindow::on_pushButton_clicked(){QMediaPlayer*player=newQMediaPlayer(this);player->setVolume(50);pl

c++ - 对 WinMain@16 C++、SDL-2 的 undefined reference

我一直收到错误undefinedreferencetoWinMain@16。为了节省空间,here'salinktoallthefilescurrentlyintheproject.目前,除了创建一个窗口、将其填充为绿色然后在角落绘制一个框外,它应该做的不多,同时通过控制台跟踪鼠标的位置。但是,它不会构建,并且出现上述错误。我的链接器库是:glew32slibSDL2mainmingw32libSDL2opengl32glew32我正在使用Codeblocks13.12和g++,遵循C++11ISOC++语言标准。如果相关的话,我的电脑使用的是Windows10。我花了很长时间试图找到

c++ - std::optional<std::reference_wrapper<T>> - 可以吗?

是std::optional>是否符合C++17的标准(或草案)?标准明确指出,引用类型的std::optional格式错误。但它是否包括reference_wrapper? 最佳答案 是的。那没问题。它不包括reference_wrapper因为reference_wapper不是引用类型。只有实际的引用类型是不允许的。 关于c++-std::optional>-可以吗?,我们在StackOverflow上找到一个类似的问题: https://stackov

c++ - shared_ptr 中对 const int 的 undefined reference

我有一个配置类//config.hppclassConfig{public:staticconstexprinta=1;staticconstexprintb=1;}并包含在main.cpp中//main.cpp#include"config.hpp"intmain(){std::coutstream=std::make_shared(Config::a);//compileerror}编译器说未定义对Config::a的引用它在使用cout时有效,但在shared_ptr构造函数中时无效。我不知道为什么会这样。 最佳答案 请注意s

c++ - 从 C++ 中同一个类的另一个成员函数中调用成员函数,Objective C

考虑以下几点:classA{//datamembersvoidfoo(){bar();//isthispossible?orshouldyousaythis->bar()notethatbarisnotstatic}voidbar(){}}//endofclassA如何从另一个内部调用成员函数?静态函数如何影响“this”的使用。应该在对象上调用函数吗? 最佳答案 Nawaz是正确的:'this'是隐含的。一个异常(exception)是如果foo是静态函数,因为在静态函数中没有“this”。在那种情况下,您不能使用bar()除非b

c++ - 当我尝试编译时带有 boost 的 undefined reference

当我尝试使用boost编译我的服务器时,我遇到了很多错误。在这里,这是我的生成文件:NAME=serveurSRCS=Serveur/main.cpp\Serveur/Client.cpp\Serveur/Commande.cpp\Serveur/My_exception.cpp\Serveur/Network.cpp\Serveur/Server.cpp#####################################################OBJS=$(SRCS:.cpp=.o)CC=g++RM=rm-fCFLAGS=-g-W-Wall-WerrorINCL=./S