c ++难题

编程入门 行业动态 更新时间:2024-10-06 18:33:38
本文介绍了c ++难题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对以下代码有疑问。什么错误行尝试 来申报?如果下一行能成功,为什么第一行失败 ?非常感谢。 A级{ 公开: A(char const *){} }; int main() { char const * a =" hello"; A(a); //错误 A((char const *)a); // ok 返回0; }

解决方案

Nan Li写道:

我对以下代码有疑问。什么错误行尝试 来申报?如果下一行能成功,为什么第一行失败 ?非常感谢。 A级{ 公开: A(char const *){} }; int main() { char const * a =" hello"; A(a); //错误 A((char const *)a); // ok 返回0; }

这里,

>> A(char const *)

i尝试给它命名,就像''a'' A(char const * a){} 然后在main中,我只是: char const * p; A(p); 它完美运行

MC felon写道:

Nan Li写道:

我对以下代码有疑问。什么错误行尝试 来申报?如果下一行能成功,为什么第一行失败 ?非常感谢。 A级{ 公开: A(char const *){} }; int main() { char const * a =" hello"; A(a); //错误 A((char const *)a); // ok 返回0; }

这里,

>> A(char const *)

i尝试给它命名,就像''a'' A(char const * a){} 然后在main中,我只是: char const * p; A(p); 完美无缺

您使用了什么编译器?我用g ++。随着你的改变,我仍然得到了相同的旧结果 。我不认为在 签名中添加一个正式参数会改变一些东西。 这里的错误行A(a)实际上是与A a相同。我还是尝试了'A(a)'','A(((a))''',......它们都是一样的。

我不知道你在说什么。在所有c ++编译器中普遍接受的代码是'b 。它是一个简单的OOP代码 ,它不使用库。无论你使用什么编译器,它都将是 相同。准确输入此代码: class a { public: a(char const * a){} }; void main() { char const * pic; a(图片); } 如果它不起作用,我会染发粉红色送你一张照片。

I have questions about the following code. What does the error line try to declare ? If the next line can succeed, why does the first one fail ? Thanks a lot. class A { public: A( char const * ) {} }; int main() { char const * a = "hello"; A(a); //error A( (char const *)a ); //ok return 0; }

解决方案

Nan Li wrote:

I have questions about the following code. What does the error line try to declare ? If the next line can succeed, why does the first one fail ? Thanks a lot. class A { public: A( char const * ) {} }; int main() { char const * a = "hello"; A(a); //error A( (char const *)a ); //ok return 0; }

here,

>>A( char const * )

i tried giving it a name, like ''a'' A(char const* a) {} and then in main, i just : char const* p; A(p); it works perfectly

MC felon wrote:

Nan Li wrote:

I have questions about the following code. What does the error line try to declare ? If the next line can succeed, why does the first one fail ? Thanks a lot. class A { public: A( char const * ) {} }; int main() { char const * a = "hello"; A(a); //error A( (char const *)a ); //ok return 0; }

here,

>>A( char const * )

i tried giving it a name, like ''a'' A(char const* a) {} and then in main, i just : char const* p; A(p); it works perfectly

What compiler did you use? I use g++. With your change, I still got the same old results. I don''t think adding a formal parameter in the signature will change things. It seems the error line A(a) here is actually the same as ''A a''. I also tried ''A (a)'', ''A(((a)))'', ... they are all the same thing.

i dont know what you''re talking about. the code is something that''s universally accepted in all compilers of c++.it''s a plain code of OOP that uses no libraries. no matter what compiler you use, it''ll be the same. enter exactly this code: class a { public: a(char const* a) {} }; void main() { char const* pic; a(pic); } if it doesn''t work, i''ll dye my hair pink and send you a pic of it.

更多推荐

c ++难题

本文发布于:2023-11-29 15:12:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646758.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:难题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!