术语用英语:) [英] Terminology in english :)

查看:133
本文介绍了术语用英语:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在我试图找到strtoupper并没有使用转换(现在已经修复了

),我发现了以下消息:


| -------------------在这里剪切---------------------

|

| #include< string>

| #include< algorithm>

| #include< cctype>

| #include< iostream

|

|使用命名空间std;

|

|的std :: string&安培; lower(std :: string& p_str)

| {

| std :: transform(p_str.begin(),p_str.end(),p_str.begin(),

tolower);


^^^^ ^^^


这应该是一个FAQ。


三个事实:


1 )std :: tolower(resp.std :: toupper)是一个重载函数。

2)C ++没有用于重载函数集的类型。

3)模板-argument deduction通过统一参数类型



函数参数类型来实现。


by point 2),point 3)不能成功,因此错误。


- Gaby


================ =


我真的不明白什么是2& 3说。点3

说如果我们有模板化函数:


<模板X> foo(X x)


然后当我们写:


foo('''')


编译器推断出在这个函数中调用X是指一个char

类型?


不知道#2在说什么点:)


相关说明:


" transform(foo.begin(),foo.end(),foo.begin(),(int(*)

(int))std :: tolower);


演员一方面导致明确的重载决议

支持该功能;它还允许编译器正确地推导出变换的第三个参数。


他的意思是我们谈论铸造导致明确的

超载分辨率支持该功能?


干杯


Taras

Hi everyone,

In me trying to find strtoupper wasn''t working with transform (which
I''ve fixed now), I came across the following message:

| ------------------- cut here ---------------------
|
| #include <string>
| #include <algorithm>
| #include <cctype>
| #include <iostream
|
| using namespace std;
|
| std::string& lower( std::string& p_str )
| {
| std::transform( p_str.begin(), p_str.end(), p_str.begin(),
tolower );

^^^^^^^

This ought to be a FAQ.

Three facts:

1) std::tolower (resp. std::toupper) is an overloaded function.
2) C++ has no type for the set of overloaded functions.
3) Template-argument deduction works by unifying the argument type
with
function parameter types.

by point 2), point 3) cannot succeed, hence the error.

-- Gaby

=================

I don''t really understand what points 2 & 3 are saying. Is point 3
saying that if we have a templated function:

<template X>foo(X x)

Then when we write:

foo(''a'')

The compiler deduces that in this function call X refers to a char
type?

No idea what point #2 is saying :)

On a related note:

" transform(foo.begin(), foo.end(), foo.begin(), (int(*)
(int))std::tolower);

The cast causes, on the one hand, an explicit overload resolution
in favour of the function; it also allows the compiler to properly
deduce the third argument to transform."

What does he mean we talking about casting causing an explicit
overload resolution in favour of the function?

Cheers

Taras

推荐答案

Taras_96写道:
Taras_96 wrote:

大家好,


在我看来试图找到strtoupper并没有使用转换(现在我已经修复了),我发现了以下消息:
Hi everyone,

In me trying to find strtoupper wasn''t working with transform (which
I''ve fixed now), I came across the following message:

> -------------------在这里剪切---------------------

#include< string>
#include< algorithm>
#include< cctype>
#include< iostream

使用命名空间std ;

std :: string& lower(std :: string& p_str)
{
std :: transform(p_str.begin(),p_str.end(),p_str.begin(),
tolower);
>------------------- cut here ---------------------

#include <string>
#include <algorithm>
#include <cctype>
#include <iostream

using namespace std;

std::string& lower( std::string& p_str )
{
std::transform( p_str.begin(), p_str.end(), p_str.begin(),
tolower );



^^^^^^^


这应该是常见问题。


三个事实:


1)std :: tolower(resp.std :: toupper)是一个重载函数。

2)C ++有没有类型的重载函数集。

3)模板参数推导通过将参数类型



函数参数类型统一起作用。


点2),点3)不能成功,因此错误。


- Gaby


=================


我真的不明白2& 3说。点3

说如果我们有模板化函数:


<模板X> foo(X x)


^^^^^^^

This ought to be a FAQ.

Three facts:

1) std::tolower (resp. std::toupper) is an overloaded function.
2) C++ has no type for the set of overloaded functions.
3) Template-argument deduction works by unifying the argument type
with
function parameter types.

by point 2), point 3) cannot succeed, hence the error.

-- Gaby

=================

I don''t really understand what points 2 & 3 are saying. Is point 3
saying that if we have a templated function:

<template X>foo(X x)



缺少返回值类型。

Return value type is missing.


>

然后我们写道:


foo('''')


编译器推断出在这个函数中调用X是指一个char

类型?
>
Then when we write:

foo(''a'')

The compiler deduces that in this function call X refers to a char
type?



是的。它被称为模板参数扣除函数

调用。

Yes. It''s called "template argument deduction from a function
call".


>

不知道#2在说什么点:)
>
No idea what point #2 is saying :)



如果我推测,可能会说没有超载

仅存在于返回值类型。或者它可能会说

在由重载函数集合形成的语言中没有泛型类型(不确定它可能有用,

但是。

If I were to speculate, it might be saying that no overloading
exists solely on the return value type. Or it might be saying
that there is no generic type in the language formed from a set
of overloaded functions (not sure what it might be useful for,
however).


>

相关说明:


transform(foo.begin(),foo.end(),foo.begin(),(int(*)

(int))std :: tolower);


演员一方面导致明确的重载决议

支持该功能;它还允许编译器正确地推导出变换的第三个参数。


他的意思是我们谈论铸造导致明确的

重载决议有利于该功能?
>
On a related note:

" transform(foo.begin(), foo.end(), foo.begin(), (int(*)
(int))std::tolower);

The cast causes, on the one hand, an explicit overload resolution
in favour of the function; it also allows the compiler to properly
deduce the third argument to transform."

What does he mean we talking about casting causing an explicit
overload resolution in favour of the function?



使用转换为函数指针时的重载分辨率

必须考虑_destination_type_。对于

示例:


int foo(int); //第1行

void foo(char);

int main(){

int(* p)(int)= foo; //选择第1行的''foo'

}


HTH


V

-

请在通过电子邮件回复时删除资金''A'

我不回复热门回复,请不要问

Overload resolution when conversion to a function pointer is used
has to take the _destination_type_ into consideration. For
example:

int foo(int); // line 1
void foo(char);
int main() {
int (*p)(int) = foo; // the ''foo'' from line 1 is picked
}

HTH

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


2008-02-28 14:07:40,James Kanze写道:
On 2008-02-28 14:07:40, James Kanze wrote:

>(int(*)(int))std :: tolower
>(int(*)(int))std::tolower


>他是什么意思我们谈论的是铸造导致显式过载
解决方案有利于该功能?
>What does he mean we talking about casting causing an explicit overload
resolution in favour of the function?



这意味着如果编译器在获取重载函数的地址时无法解决重载

,则该语言具有

提供了一个黑客,所以我们可以手动指定我们想要的功能。

从语法上讲,它是一个演员,但在语义上,它没有做一个

转换,但指定了我们期望的类型实际上是什么。


(请注意,这有点棘手。如果我用
$替换std :: tolower b $ b函数没有超载,并且签名不同于

给定的一个,它*是*转换。)


It means that in cases where the compiler cannot resolve overloading
when taking the address of an overloaded function, the language has
provided a hack so we can manually specify which function we want.
Syntactically, it''s a cast, but semantically, it doesn''t do a
conversion, but specifies what we expect the type to actually be.

(Note that this is a bit tricky. If I replace std::tolower with a
function that isn''t overloaded, and which has a different signature than
the one given, it *is* a conversion.)



有没有办法明确指定哪些重载使用

如果没有完全匹配就会失败?


Gerhard

Is there a way to explicitly specify which of the overloads to use that
fails if there isn''t an exact match?

Gerhard


Gerhard Fiedler写道:
Gerhard Fiedler wrote:

...

有没有办法明确指定哪个重载使用那个

如果没有完全匹配则会失败?

...
...
Is there a way to explicitly specify which of the overloads to use that
fails if there isn''t an exact match?
...



使用模板参数的显式规范而不是强制转换 - 如果没有完全匹配,它将会失败



std :: transform<

std :: string :: iterator,

std :: string :: iterator,

int(*)(int)>(p_str.begin (),p_str.end(),p_str.begin(),std :: tolower)


不幸的是,在这种情况下,模糊参数是三个中的最后一个,

这意味着我们必须明确指定所有这些。


-

祝你好运,

Andrey Tarasevich

Use explicit specification of template arguments instead of a cast - it will
fail if there''s no exact match

std::transform<
std::string::iterator,
std::string::iterator,
int(*)(int)>( p_str.begin(), p_str.end(), p_str.begin(), std::tolower )

Unfortunately, in this case the ambiguous parameter is the last one of three,
which means that we have to specify all of them explicitly.

--
Best regards,
Andrey Tarasevich


这篇关于术语用英语:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆