jjzjj

cross-reference

全部标签

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++ - 当我尝试编译时带有 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

c++ - decltype - "the only context in which a variable defined as a reference is not treated as a synonym for the object to which it refers"?

我正在阅读C++Primer,第5版,第1页。71他们首先给出了这个代码示例:constintci=0,&cj=ci;decltype(ci)x=0;decltype(cj)y=x;decltype(cj)z;//error然后他们说:Itisworthnotingthatdecltypeistheonlycontextinwhichavariabledefinedasareferenceisnottreatedasasynonymfortheobjecttowhichitrefers.这是什么意思?我不明白。y指的是x。那么有什么收获呢? 最佳答案

C++ 错误 : reference to non-static member function must be called

我正在尝试创建一个类来抽象libuv网络功能的一些基本行为。#defineTCP_BACKLOG256class_tcp{uv_tcp_t*tcp=NULL;public:~_tcp(){deletetcp;}voidlisten_uv_listen_uv_connection_cb(uv_stream_t*stream,intstatus){printf("NEWCONNECTION\n");}voidlisten(constchar*host,intport){tcp=newuv_tcp_t();uv_tcp_init(uv_default_loop(),tcp);sockaddr

c++ - reference_wrapper : make_pair VS Class Template Argument Deduction (CTAD)

为什么make_pair和类模板参数推导(CTAD)不同意生成哪种类型?#include#include#include#includeintmain(){intmyInt=5;std::reference_wrappermyIntRef=myInt;automyPair=std::make_pair(myInt,myIntRef);std::pairMy2ndPair(myInt,myIntRef);std::cout输出:St4pairIiRiE//std::pairSt4pairIiSt17reference_wrapperIiEE//std::pair>更新:为什么std::p

c++ - 数组 : Storing Objects or References

作为一名Java开发人员,我有以下C++问题。如果我有类型A的对象并且我想将它们的集合存储在一个数组中,那么我应该只存储指向对象的指针还是存储对象本身更好?在我看来,存储指针更好,因为:1)通过将对象的指针设置为null,可以很容易地删除对象2)节省空间。 最佳答案 指针还是对象?在C++中不能将引用放在数组中。您可以制作一个指针数组,但我仍然更喜欢容器和实际对象而不是指针,因为:没有机会泄漏,异常安全更容易处理。它并没有减少空间——如果你存储一个指针数组,你需要对象的内存加上指针的内存。我唯一提倡将指针(或智能指针会更好)放入容器

c++ - 如何在编译时检测 C++ 中的 std::reference_wrapper

假设我们有一些可变参数模板,需要以不同方式处理std::reference_wrapper参数。我们怎样才能做到这一点? 最佳答案 你可以做一个特征来判断一个类型是否是reference_wrappertemplatestructis_reference_wrapper:false_type{};templatestructis_reference_wrapper>:true_type{};然后你可以用它来消除歧义:templatevoiddo_stuff(T&&t,false_type){coutvoiddo_stuff(T&&r

c++ - undefined reference 和非虚拟 thunk

这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭9年前。我有这样的类(class):classProduct{public:virtualdoublegetPrice();virtualvoidsetPrice(doubleprice);};classMusicProduct{protected:stringauthor;doubleprice;public:virtualstringgetAuthor();v

c++ - 对 B::B & B::~B 的 undefined reference

我不断收到g++编译器的投诉,说下面的代码有问题。仔细检查后,我还是想不通为什么从embedMain.cpp中找不到B类的构造函数和析构函数。谁能给我一点提示?谢谢//embedMain.cpp#include"embed.h"intmain(void){Bb("helloworld");return0;},//embed.h#ifndefEMBED_H#defineEMBED_H#includeclassB{public:B(conststd::string&_name);~B();private:std::stringname;};#endif,//embed.cpp#includ