传递给省略号时的默认转换 [英] Default conversion when passing to an ellipsis
问题描述
我有一个类String,它实现了const char *()运算符。我今天做了一些测试,并做了类似的事情:
字符串测试(hello world);
printf("%) s\\\
,测试); //而不是test.c_str();或者(const
char *)测试
此代码在x86 / visual studio 7.1上编译并正常工作。在一些其他平台上,gcc正在给出错误,正如我所料。
所以我想知道视觉工作室是否允许某些内容<标准禁止
,或者当对象实例传递给
时,是否有办法强制调用默认的
转换运算符省略号?
谢谢,
/ d
Hi,
I have a class String which implements the const char*() operator. I
was doing some tests today and did something like:
String test( "hello world" );
printf( "%s\n", test ); // instead of test.c_str(); or (const
char*)test
This code compiled and worked fine on a x86/visual studio 7.1. On some
other platforms, gcc was giving errors, as i would expect.
So i''m wondering if visual studio is allowing something which is
forbidden by the standard, or is there a way to force a default
conversion operator to be called when an object instance is passed to
an ellipsis?
Thanks,
/d
推荐答案
也许Visual Studio在字符串上定义了
运算符char const *
Kufa写道:
Perhaps Visual Studio defines
operator char const *
on strings?
Kufa wrote:
我有一个类String,它实现了const char *()运算符。我今天做了一些测试并做了类似的事情:
字符串测试(hello world);
printf("%s \ n",test); //而不是test.c_str();或(const
char *)测试
此代码在x86 / visual studio 7.1上编译并正常工作。在一些其他平台上,正如我所料,gcc给出了错误。
所以我想知道视觉工作室是否允许标准禁止的内容,或者有没有办法强制在对象实例传递给省略号时调用默认的转换操作符?
谢谢,
/ d
Hi,
I have a class String which implements the const char*() operator. I
was doing some tests today and did something like:
String test( "hello world" );
printf( "%s\n", test ); // instead of test.c_str(); or (const
char*)test
This code compiled and worked fine on a x86/visual studio 7.1. On some
other platforms, gcc was giving errors, as i would expect.
So i''m wondering if visual studio is allowing something which is
forbidden by the standard, or is there a way to force a default
conversion operator to be called when an object instance is passed to
an ellipsis?
Thanks,
/d
abose写道:
也许Visual Studio定义了
operator char const *
在字符串上?
Perhaps Visual Studio defines
operator char const *
on strings?
这是一个自定义的String类。
/ k
This is a custom String class.
/k
Kufa写道:
我有一个类String,它实现了const char *()运算符。我今天做了一些测试并做了类似的事情:
字符串测试(hello world);
printf("%s \ n",test); //而不是test.c_str();或(const
char *)测试
此代码在x86 / visual studio 7.1上编译并正常工作。在一些其他平台上,正如我所料,gcc给出了错误。
所以我想知道视觉工作室是否允许标准禁止的内容,或者有没有办法强制在对象实例传递给省略号时调用默认的转换操作符?
I have a class String which implements the const char*() operator. I
was doing some tests today and did something like:
String test( "hello world" );
printf( "%s\n", test ); // instead of test.c_str(); or (const
char*)test
This code compiled and worked fine on a x86/visual studio 7.1. On some
other platforms, gcc was giving errors, as i would expect.
So i''m wondering if visual studio is allowing something which is
forbidden by the standard, or is there a way to force a default
conversion operator to be called when an object instance is passed to
an ellipsis?
如果你需要Visual-C ++特定信息,请考虑在''microsoft.public.vc.language''中询问
。
自''String''这是一个对象,将它传递给一个带有
省略号的函数会导致未定义的行为(5.2.2 / 7)。
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复最热门的回复,请不要''请问
If you need Visual-C++-specific information, please consider asking
in ''microsoft.public.vc.language''.
Since ''String'' here is an object, passing it to a function with the
ellipsis causes undefined behaviour (5.2.2/7).
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
这篇关于传递给省略号时的默认转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!