草庐IT

char_type

全部标签

使用 unique_ptr 包含 char 数组的 C++ 对象

我正在寻找一种方法来使用unique_ptr来分配一个结构,该结构包含一个char数组,其中包含动态设置的字节数以支持不同类型的消息。假设:structMyMessage{uint32_tid;uint32_tdata_size;chardata[4];};如何将下面的send_message()转换为使用智能指针?voidsend_message(void*data,constsize_tdata_size){constautomessage_size=sizeof(MyMessage)-4+data_size;constautomsg=reinterpret_cast(newcha

c++ - gcc 相对于在新表达式中解析 type-id 发出错误

这个程序#includeintmain(){conststd::size_tN1=2;conststd::size_tN2=3;int(**p)[N1]=new(int(*[N2])[N1]);}doesnotcompile使用编译器C++gccHEAD10.0.020190。编译器报错prog.cc:Inlambdafunction:prog.cc:8:40:error:expected'{'before')'token8|int(**p)[N1]=new(int(*[N2])[N1]);|^prog.cc:Infunction'intmain()':prog.cc:8:34:err

c++ - boost::serialization Archive::register_type 如何工作?

boost::serialization能够序列化它们最派生类的多态对象,即使这些对象由指向基类的引用/指针指向。这不需要虚函数。要做到这一点,boost::serialization需要知道存在的多态类型:Archive::register_type必须在Archive用于序列化的对象。Thisexample展示了如何注册类型以及如何序列化它们。我想知道这是如何实现的。我试图查看boost::serialization源代码但失败了:我不太擅长模板元编程。 最佳答案 boost.serialization可以使用typeid()或

c++ - 为什么 ostream::operator<< 是 char 参数的全局函数?

根据http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/operator 最佳答案 operator对于streambuf*(或int这听起来更简单)和char既可以作为成员(member)运营商实现,也可以作为非成员(member)(免费)运营商实现。我的猜测是,这是由于在定义C++时出现了追溯兼容性问题:可能较旧的代码依赖于成员operator,因此他们决定不将其作为免费运营商移动。C++标准库(以及STL)有许多像这样的不均匀性。

错误的“缺失必需参数:Grant_Type”使用Swift 3

我在TwitterAPI上工作,我想获得access_token,但我遇到了这个错误:{"errors":[{"message":"Missingrequiredparameter:grant_type","label":"forbidden_missing_parameter","code":170}]}.我的要求如下:letdict=["grant_type":"client_credentials"]requestPOSTURL("https://api.twitter.com/oauth2/token",params:dictas[String:AnyObject],headers:[

Name for argument of type [java.lang.String] not ... Ensure that the compiler uses the ‘-parameters’

更多信息:https://oldmoon.top/post/191简介使用最新版的Springboot3.2.1搭建开发环境进行开发,调用接口时出现奇怪的错。报错主要信息如下:Nameforargumentoftype[java.lang.String]notspecified,andparameternameinformationnotavailableviareflection.Ensurethatthecompilerusesthe‘-parameters’flag.官方说明中一直强调@PathVariable的使用,并没有提及@RequestParam,阅读官方文档@RequestPa

c++ - 错误 : Invalid use of incomplete type struct Subject; error: forward declaration of struct Subject

我继承自模板类。当我进入教师类(class)时,我想进入学科类(class),反之亦然。我收到错误InvaliduseofincompletetypestructSubect;voidaddSubject(Subject*s){this->addReference(s);s->addReference(this);whenIcommentthislinetheitcompileswithouterrors,butIcannotinsertintoSubject}我的全部代码在下面#include#include#includeusingnamespacestd;classSubject

c++ - 如何专门化模板函数以让它接受将 char 数组作为参数传递?

//problem.cpp:#includetemplatevoidfunc(constT&v);intmain(){inti;floatf;char*cp;charca[4];func(i);func(f);func(cp);func(std::string("std::string"));func(ca);func("string_literal");return0;}//problem2.cpp#includetemplatevoidfunc(constT&v);//undefinedreferenceto`voidfunc(intconst&)'templatevoidfunc

C++ 编译器错误 "cannot be thread-local because it has non-POD type”“

这个声明:___threadAa;生成此错误:cannotbethread-localbecauseithasnon-PODtypeA在哪里classA{public://functiondeclarationprivate://datamembers};我正在尝试使用命令ogsincludes&ogsmk在Linux上进行编译。我们有静态线程,即在我们的应用程序进入之前,我们知道线程的数量,因此目前的工作是通过声明A的数组来完成的,即Aa[Numberofthreads].我该如何解决这个问题? 最佳答案 假设您使用gcc,线程本

c++ - MFC C++ 如何在 MessageBox 中显示一个 const char 值?

我希望标题足够好,可以帮助解释需要什么。在解决了这么多之后,我的项目应该完成了。当我这样做的时候chare[1000]="HELLO";CStringmsg;msg.Format(_T("%s"),e);MessageBox(msg);消息框只是向我显示诸如“㹙癞鞮㹙癞鞮”之类的随机词,而不是我想要的“HELLO”。我该如何解决这个问题??帮助将不胜感激。谢谢你 最佳答案 首先,您真的以这种方式使用MessageBoxAPI吗?检查MSDNDocumentation.现在回答你的问题,chare[1000]="HELLO";CStr