草庐IT

char_type

全部标签

c++ - "Expected ' (' for function-style cast or type construction"错误是什么意思?

我收到错误“Expected'('forfunction-stylecastortypeconstruction”,我已尽力在线研究此错误的含义,但无法找到导致此错误的任何文档错误。我在StackOverflow上发现的所有相关问题都修复了特定的代码片段,并且没有更笼统地解释导致错误的原因。这些包括Expected'('forfunction-stylecastortypeconstruction答案突出了代码的几个问题。究竟是哪个问题导致了错误尚不清楚。c++Xcodeexpected'('forfunction-stylecastortypeconstruction在主函数中定义函

C++14 元编程 : Automagically build a list of types at compile/init time

使用C++14和CuriouslyRecurringTemplatePattern(CRTP)以及可能的Boost.Hana的某种组合(或boost::mpl如果您愿意),我可以在编译时(或静态初始化时)构建一个类型列表而无需显式声明吗?例如,我有这样的东西(在Coliru上查看):#include#include#includenamespace{structD1{staticconstexprautoval=10;};structD2{staticconstexprautoval=20;};structD3{staticconstexprautoval=30;};}intmain(

c++ - 从常量初始化 char 数组

我从这段代码开始:voidfunc1(){chartmpfile[]="/tmp/tmpXXXXXX";mkstemp(tmpfile);//Note:mkstempmodifiesthechararray,cannotbeconst...}voidfunc2(){chartmpfile[]="/tmp/tmpXXXXXX";mkstemp(tmpfile);//Note:mkstempmodifiesthechararray,cannotbeconst...}我想重构它以提取共享的"/tmp/tmpXXXXXX"常量。这是一个尝试:constexprcharkTmpfile[]="/

c++ - 在 C++ 中将整数存储到 char* 中

我正在编写一些返回整数的代码,然后需要使用ncurses库中的printw输出该整数。但是,由于printw只接受char*,我不知道如何输出它。本质上,有没有一种方法可以将整数存储到char数组中,或者使用printw输出整数? 最佳答案 printw()接受constchar*作为格式说明符。你想要的是printw("%d",yournumber); 关于c++-在C++中将整数存储到char*中,我们在StackOverflow上找到一个类似的问题: h

c++ - template<class key, class type> 在 C++ 中的方法之前是什么意思?

我有这段代码,我试图理解遵循的约定,.cpp文件中定义的所有方法都有template写在他们面前。这是什么意思?例子://ConstructortemplateMyOperation::MyOperation(){//methodimplementation}//AmethodtemplateMyOperation::otherOperation(){//methodimplementation}谢谢 最佳答案 必须已经有一个很好的答案,但我也会把我的也扔进池中。C++允许程序结构的声明和实现分开进行。它源于C/C++程序员如何相互

c++ - "signed char"和 "unsigned char"能否始终相互转换而不丢失数据?

在C++中,我们可以使用signedchar和unsignedchar,它们的大小相同但值的范围不同。在下面的代码中:signedcharsignedChar=-10;unsignedcharunsignedChar=static_cast(signedChar);signedChar=static_cast(unsignedChar);无论其原始值是多少,signedchar都会保留其值吗? 最佳答案 不,没有这样的保证。从signedchar到unsignedchar的转换是明确定义的,就像C++(和C)中的所有有符号到无符号整

c++ - 函数模板 : Different specializations with type traits

考虑到类模板,可以使用类型特征和虚拟启动器模板参数为某些类型的组提供模板特化。我已经askedthatearlier.现在,对于函数模板,我需要同样的东西:即,我有一个模板函数,并且想要对一组类型进行特化,例如,作为类X的子类型的所有类型>。我可以用这样的类型特征来表达这一点:std::enable_if::value>::type我想过这样做:templatevoidfoo(){//Dosomething}templatevoidfoo::value>::type>(){//Dosomethingdifferent}但是,这不起作用,因为函数模板不允许偏特化。那怎么办呢?也许是类型特

c++ - unsigned char ** 到 opencv mat

我快到了,但我不太明白如何转换unsignedchar**toacv::Mat我知道cv::Mat的.data部分是uchar*我正在使用一个以...的形式返回和图像的函数unsignedchar**output;但我的其余代码使用cv::Mat的。我也没有我正在使用的库的源代码,所以我真的不知道它在做什么。编辑谢谢大家的帮助,我已经做到了...cv::MatTempMat=cv::Mat(h,w,CV_8UC1,*output);imshow("thisisatest",TempMat);但是图像是黑色的,所以我现在需要查明那里是否真的有任何东西。很抱歉缺乏研究,我的截止日期很紧,不

C++ 错误 : Type Name is Not Allowed

我正在尝试学习指针参数中的新类(class),我想让函数senior和everyoneElse接受指针x,但是当我尝试使用指针pAge调用函数时,它显示错误:类型名称是不允许的。怎么了?#includeintsenior(int*x);inteveryoneElse(int*x);usingnamespacestd;intmain(){intage(0);int*pAge(&age);cout>age;if(age>59)senior(int*pAge);elseeveryoneElse(int*pAge);return0;}intsenior(int*x){return*x;}int

C++ 连接字符串导致 "invalid operands of types ‘const char*’ 和 ‘const char"

我想连接两个字符串,但出现错误,我不知道如何克服这个错误。有什么方法可以将这个constchar*转换为char吗?我应该使用一些取消引用吗?../src/main.cpp:38:error:invalidoperandsoftypes‘constchar*’and‘constchar[2]’tobinary‘operator+’make:***[src/main.o]Error1但是,如果我尝试以这种方式组成“bottom”字符串,它会起作用:bottom+="|";bottom+=tmp[j];bottom+="";这是代码。#include#include#include#inc