Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C+中的复杂常量声明+; 我将第一次进入C++,特别是谷歌Re2库,并且我被困在了一些语法上。我正在尝试调用具有以下签名的函数: static bool FindAndConsumeN(StringPiece* input, const RE2& pattern, const Arg* const args[], int argc);_C++_Constants_Re2 - Fatal编程技术网

C+中的复杂常量声明+; 我将第一次进入C++,特别是谷歌Re2库,并且我被困在了一些语法上。我正在尝试调用具有以下签名的函数: static bool FindAndConsumeN(StringPiece* input, const RE2& pattern, const Arg* const args[], int argc);

C+中的复杂常量声明+; 我将第一次进入C++,特别是谷歌Re2库,并且我被困在了一些语法上。我正在尝试调用具有以下签名的函数: static bool FindAndConsumeN(StringPiece* input, const RE2& pattern, const Arg* const args[], int argc);,c++,constants,re2,C++,Constants,Re2,使用代码: const re2::RE2::Arg match; bool isMatched = RE2::FindAndConsumeN(&inputPiece, *expression,new const re2::RE2::Arg[] { &match },0) 但是,我得到了编译器错误: Error 3 error C2664: 're2::RE2::FindAndConsumeN' : cannot convert parameter 3 from 'con

使用代码:

const re2::RE2::Arg match;
bool isMatched = RE2::FindAndConsumeN(&inputPiece, *expression,new const re2::RE2::Arg[] { &match },0)
但是,我得到了编译器错误:

Error   3   error C2664: 're2::RE2::FindAndConsumeN' : cannot convert parameter 3 from 'const re2::RE2::Arg (*)[]' to 'const re2::RE2::Arg *const []'
我显然把第三个参数的数据类型搞错了,但是有人知道正确的数据类型是什么吗


我正在使用Visual Studio 2010编译代码这里的问题是需要指向常量数据的指针,而不是指向数据的常量指针。使用中间变量存储有问题的参数的值,我认为您可以对问题进行排序。

这里的问题是您需要指向常量数据的指针,而不是指向数据的常量指针。使用中间变量来存储有问题的参数的值,我认为您可以对问题进行排序。

首先,请注意,参数声明的含义略有不同 当它们显示为函数参数时。在本例中,实际类型为 第三个参数的值是:
Arg const*const*
。我认为你做不到 在这里使用
新表达式
(如果可以,谁会删除它);新的 所需的表达式类似于
new(Arg const*const
[n] )
;它分配一个
n
未初始化常量指针数组。 您需要的是更符合以下内容的东西:

std::vector<Arg const*> args;
//  Fill out args with the desired data...
... , &args[0], ...
std::vector args;
//用所需数据填写args。。。
... , &args[0]。。。

首先,请注意参数声明的含义略有不同 当它们显示为函数参数时。在本例中,实际类型为 第三个参数的值是:
Arg const*const*
。我认为你做不到 在这里使用
新表达式
(如果可以,谁会删除它);新的 所需的表达式类似于
new(Arg const*const
[n] )
;它分配一个
n
未初始化常量指针数组。 您需要的是更符合以下内容的东西:

std::vector<Arg const*> args;
//  Fill out args with the desired data...
... , &args[0], ...
std::vector args;
//用所需数据填写args。。。
... , &args[0]。。。

函数签名是:

static bool FindAndConsumeN(StringPiece* input, const RE2& pattern,
                            const Arg* const args[], int argc);
第三个参数是const Arg*const args[],这意味着: 指向Arg类型的常量指针的常量数组


i、 e.数组是常量,每个条目也是常量。

函数签名是:

static bool FindAndConsumeN(StringPiece* input, const RE2& pattern,
                            const Arg* const args[], int argc);
第三个参数是const Arg*const args[],这意味着: 指向Arg类型的常量指针的常量数组


i、 e.数组是常量,每个条目也是常量。

您应该使用如下代码:

re2::RE2::Arg match;
re2::RE2::Arg* args[] = { &match };
re2::RE2::FindAndConsumeN(NULL, pattern, args, 1);
args
将转换为
const Arg*args[]

内部
常量
与调用代码无关,它只在
find和consumen
中工作

不要使用
new
,因为以后无法
delete
数组。

(使用
new
将是
new const re2::re2::Arg*[]

您应该使用如下代码:

re2::RE2::Arg match;
re2::RE2::Arg* args[] = { &match };
re2::RE2::FindAndConsumeN(NULL, pattern, args, 1);
args
将转换为
const Arg*args[]

内部
常量
与调用代码无关,它只在
find和consumen
中工作

不要使用
new
,因为以后无法
delete
数组。

(使用
new
它将是
new const re2::re2::Arg*[]

这不是例外,是编译器错误。看到它时按F1键。另外,请先学习该语言
NULL
不是
0
@Abyx:另外,请先阅读标准,
NULL
是“值为0的整型常量表达式”。Abyx注释很可笑,0与int argc参数匹配。使用
NULL
代替
int
将导致编译器发出警告,至少对某些编译器来说,这不是例外,这是编译器错误。看到它时按F1键。另外,请先学习该语言
NULL
不是
0
@Abyx:另外,请先阅读标准,
NULL
是“值为0的整型常量表达式”。Abyx注释很可笑,0与int argc参数匹配。使用
NULL
代替
int
将导致编译器发出警告,至少有一些编译器。你能扩展一下吗,或者给我指出一些可以更全面解释的资源的方向吗?你能扩展一下吗,或者给我指出一些可以更全面解释的资源的方向吗?谢谢mark,但我更想知道如何构造一个这种类型的对象来传递。谢谢mark,但我更想知道如何构造一个要传入的那种类型的对象。除此之外,参数列表中的
const
只是保证函数不会修改传入的内容。在声明参数时,始终可以提供非
常量
。您只需为它提供正确的基类型即可。除此之外,参数列表中的
常量
只是保证函数不会修改您传入的内容。在声明参数时,始终可以提供非
常量
。您只需要为它提供正确的基类型。